diff --git a/.travis.yml b/.travis.yml index fd3850e4..971b46a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,6 +56,7 @@ install: - go get -u github.com/hashicorp/go-version - go get -u github.com/satori/go.uuid - go get -u github.com/Sirupsen/logrus + - go get -u github.com/pkg/errors script: - go test -v -race ./... diff --git a/conn.go b/conn.go index 75b8bfb3..da8ed655 100644 --- a/conn.go +++ b/conn.go @@ -6,7 +6,6 @@ import ( "crypto/tls" "encoding/binary" "encoding/hex" - "errors" "fmt" "io" "net" @@ -21,6 +20,8 @@ import ( "sync/atomic" "time" + "github.com/pkg/errors" + "github.com/jackc/pgx/pgio" "github.com/jackc/pgx/pgproto3" "github.com/jackc/pgx/pgtype" @@ -778,7 +779,7 @@ func (c *Conn) prepareEx(name, sql string, opts *PrepareExOptions) (ps *Prepared } if len(opts.ParameterOIDs) > 65535 { - return nil, fmt.Errorf("Number of PrepareExOptions ParameterOIDs must be between 0 and 65535, received %d", len(opts.ParameterOIDs)) + return nil, errors.Errorf("Number of PrepareExOptions ParameterOIDs must be between 0 and 65535, received %d", len(opts.ParameterOIDs)) } buf := appendParse(c.wbuf, name, sql, opts.ParameterOIDs) @@ -809,7 +810,7 @@ func (c *Conn) prepareEx(name, sql string, opts *PrepareExOptions) (ps *Prepared ps.ParameterOIDs = c.rxParameterDescription(msg) if len(ps.ParameterOIDs) > 65535 && softErr == nil { - softErr = fmt.Errorf("PostgreSQL supports maximum of 65535 parameters, received %d", len(ps.ParameterOIDs)) + softErr = errors.Errorf("PostgreSQL supports maximum of 65535 parameters, received %d", len(ps.ParameterOIDs)) } case *pgproto3.RowDescription: ps.FieldDescriptions = c.rxRowDescription(msg) @@ -822,7 +823,7 @@ func (c *Conn) prepareEx(name, sql string, opts *PrepareExOptions) (ps *Prepared ps.FieldDescriptions[i].FormatCode = TextFormatCode } } else { - return nil, fmt.Errorf("unknown oid: %d", ps.FieldDescriptions[i].DataType) + return nil, errors.Errorf("unknown oid: %d", ps.FieldDescriptions[i].DataType) } } case *pgproto3.ReadyForQuery: @@ -1029,7 +1030,7 @@ func (c *Conn) sendSimpleQuery(sql string, args ...interface{}) error { func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}) (err error) { if len(ps.ParameterOIDs) != len(arguments) { - return fmt.Errorf("Prepared statement \"%v\" requires %d parameters, but %d were provided", ps.Name, len(ps.ParameterOIDs), len(arguments)) + return errors.Errorf("Prepared statement \"%v\" requires %d parameters, but %d were provided", ps.Name, len(ps.ParameterOIDs), len(arguments)) } if err := c.ensureConnectionReadyForQuery(); err != nil { @@ -1392,7 +1393,7 @@ func (c *Conn) cancelQuery() { _, err = cancelConn.Read(buf) if err != io.EOF { - return fmt.Errorf("Server failed to close connection after cancel query request: %v %v", err, buf) + return errors.Errorf("Server failed to close connection after cancel query request: %v %v", err, buf) } return nil @@ -1516,11 +1517,11 @@ func (c *Conn) execEx(ctx context.Context, sql string, options *QueryExOptions, func (c *Conn) buildOneRoundTripExec(buf []byte, sql string, options *QueryExOptions, arguments []interface{}) ([]byte, error) { if len(arguments) != len(options.ParameterOIDs) { - return nil, fmt.Errorf("mismatched number of arguments (%d) and options.ParameterOIDs (%d)", len(arguments), len(options.ParameterOIDs)) + return nil, errors.Errorf("mismatched number of arguments (%d) and options.ParameterOIDs (%d)", len(arguments), len(options.ParameterOIDs)) } if len(options.ParameterOIDs) > 65535 { - return nil, fmt.Errorf("Number of QueryExOptions ParameterOIDs must be between 0 and 65535, received %d", len(options.ParameterOIDs)) + return nil, errors.Errorf("Number of QueryExOptions ParameterOIDs must be between 0 and 65535, received %d", len(options.ParameterOIDs)) } buf = appendParse(buf, "", sql, options.ParameterOIDs) diff --git a/conn_pool.go b/conn_pool.go index 40c58f49..5fa923b7 100644 --- a/conn_pool.go +++ b/conn_pool.go @@ -2,10 +2,11 @@ package pgx import ( "context" - "errors" "sync" "time" + "github.com/pkg/errors" + "github.com/jackc/pgx/pgtype" ) diff --git a/conn_pool_test.go b/conn_pool_test.go index 4e0dc199..ccc38ba9 100644 --- a/conn_pool_test.go +++ b/conn_pool_test.go @@ -2,13 +2,14 @@ package pgx_test import ( "context" - "errors" "fmt" "net" "sync" "testing" "time" + "github.com/pkg/errors" + "github.com/jackc/pgx" ) diff --git a/copy_from.go b/copy_from.go index f3c77109..8b7c3d5b 100644 --- a/copy_from.go +++ b/copy_from.go @@ -6,6 +6,7 @@ import ( "github.com/jackc/pgx/pgio" "github.com/jackc/pgx/pgproto3" + "github.com/pkg/errors" ) // CopyFromRows returns a CopyFromSource interface over the provided rows slice @@ -156,7 +157,7 @@ func (ct *copyFrom) run() (int, error) { } if len(values) != len(ct.columnNames) { ct.cancelCopyIn() - return 0, fmt.Errorf("expected %d values, got %d values", len(ct.columnNames), len(values)) + return 0, errors.Errorf("expected %d values, got %d values", len(ct.columnNames), len(values)) } buf = pgio.AppendInt16(buf, int16(len(ct.columnNames))) diff --git a/copy_from_test.go b/copy_from_test.go index 6df4ebb1..ec674855 100644 --- a/copy_from_test.go +++ b/copy_from_test.go @@ -1,12 +1,12 @@ package pgx_test import ( - "fmt" "reflect" "testing" "time" "github.com/jackc/pgx" + "github.com/pkg/errors" ) func TestConnCopyFromSmall(t *testing.T) { @@ -186,7 +186,7 @@ func (cfs *clientFailSource) Next() bool { func (cfs *clientFailSource) Values() ([]interface{}, error) { if cfs.count == 3 { - cfs.err = fmt.Errorf("client error") + cfs.err = errors.Errorf("client error") return nil, cfs.err } return []interface{}{make([]byte, 100000)}, nil @@ -381,7 +381,7 @@ func (cfs *clientFinalErrSource) Values() ([]interface{}, error) { } func (cfs *clientFinalErrSource) Err() error { - return fmt.Errorf("final error") + return errors.Errorf("final error") } func TestConnCopyFromCopyFromSourceErrorEnd(t *testing.T) { diff --git a/example_custom_type_test.go b/example_custom_type_test.go index 66ed6c53..d3cc9085 100644 --- a/example_custom_type_test.go +++ b/example_custom_type_test.go @@ -7,6 +7,7 @@ import ( "github.com/jackc/pgx" "github.com/jackc/pgx/pgtype" + "github.com/pkg/errors" ) var pointRegexp *regexp.Regexp = regexp.MustCompile(`^\((.*),(.*)\)$`) @@ -18,7 +19,7 @@ type Point struct { } func (dst *Point) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Point", src) + return errors.Errorf("cannot convert %v to Point", src) } func (dst *Point) Get() interface{} { @@ -33,7 +34,7 @@ func (dst *Point) Get() interface{} { } func (src *Point) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Point) DecodeText(ci *pgtype.ConnInfo, src []byte) error { @@ -45,16 +46,16 @@ func (dst *Point) DecodeText(ci *pgtype.ConnInfo, src []byte) error { s := string(src) match := pointRegexp.FindStringSubmatch(s) if match == nil { - return fmt.Errorf("Received invalid point: %v", s) + return errors.Errorf("Received invalid point: %v", s) } x, err := strconv.ParseFloat(match[1], 64) if err != nil { - return fmt.Errorf("Received invalid point: %v", s) + return errors.Errorf("Received invalid point: %v", s) } y, err := strconv.ParseFloat(match[2], 64) if err != nil { - return fmt.Errorf("Received invalid point: %v", s) + return errors.Errorf("Received invalid point: %v", s) } *dst = Point{X: x, Y: y, Status: pgtype.Present} diff --git a/internal/sanitize/sanitize.go b/internal/sanitize/sanitize.go index 92b892b9..53543b89 100644 --- a/internal/sanitize/sanitize.go +++ b/internal/sanitize/sanitize.go @@ -3,11 +3,12 @@ package sanitize import ( "bytes" "encoding/hex" - "fmt" "strconv" "strings" "time" "unicode/utf8" + + "github.com/pkg/errors" ) // Part is either a string or an int. A string is raw SQL. An int is a @@ -30,7 +31,7 @@ func (q *Query) Sanitize(args ...interface{}) (string, error) { case int: argIdx := part - 1 if argIdx >= len(args) { - return "", fmt.Errorf("insufficient arguments") + return "", errors.Errorf("insufficient arguments") } arg := args[argIdx] switch arg := arg.(type) { @@ -49,18 +50,18 @@ func (q *Query) Sanitize(args ...interface{}) (string, error) { case time.Time: str = arg.Format("'2006-01-02 15:04:05.999999999Z07:00:00'") default: - return "", fmt.Errorf("invalid arg type: %T", arg) + return "", errors.Errorf("invalid arg type: %T", arg) } argUse[argIdx] = true default: - return "", fmt.Errorf("invalid Part type: %T", part) + return "", errors.Errorf("invalid Part type: %T", part) } buf.WriteString(str) } for i, used := range argUse { if !used { - return "", fmt.Errorf("unused argument: %d", i) + return "", errors.Errorf("unused argument: %d", i) } } return buf.String(), nil diff --git a/logger.go b/logger.go index c2df1d7d..528698b1 100644 --- a/logger.go +++ b/logger.go @@ -2,8 +2,9 @@ package pgx import ( "encoding/hex" - "errors" "fmt" + + "github.com/pkg/errors" ) // The values for log levels are chosen such that the zero value means that no diff --git a/pgmock/pgmock.go b/pgmock/pgmock.go index b3a51729..5e340881 100644 --- a/pgmock/pgmock.go +++ b/pgmock/pgmock.go @@ -1,12 +1,12 @@ package pgmock import ( - "errors" - "fmt" "io" "net" "reflect" + "github.com/pkg/errors" + "github.com/jackc/pgx/pgproto3" "github.com/jackc/pgx/pgtype" ) @@ -115,7 +115,7 @@ func (e *expectMessageStep) Step(backend *pgproto3.Backend) error { } if !reflect.DeepEqual(msg, e.want) { - return fmt.Errorf("msg => %#v, e.want => %#v", msg, e.want) + return errors.Errorf("msg => %#v, e.want => %#v", msg, e.want) } return nil @@ -137,7 +137,7 @@ func (e *expectStartupMessageStep) Step(backend *pgproto3.Backend) error { } if !reflect.DeepEqual(msg, e.want) { - return fmt.Errorf("msg => %#v, e.want => %#v", msg, e.want) + return errors.Errorf("msg => %#v, e.want => %#v", msg, e.want) } return nil @@ -475,22 +475,22 @@ func buildDataRow(values []interface{}, formatCodes []int16) (*pgproto3.DataRow, if e, ok := values[i].(pgtype.TextEncoder); ok { buf, err := e.EncodeText(nil, nil) if err != nil { - return nil, fmt.Errorf("failed to encode values[%d]", i) + return nil, errors.Errorf("failed to encode values[%d]", i) } dr.Values[i] = buf } else { - return nil, fmt.Errorf("values[%d] does not implement TextExcoder", i) + return nil, errors.Errorf("values[%d] does not implement TextExcoder", i) } case pgproto3.BinaryFormat: if e, ok := values[i].(pgtype.BinaryEncoder); ok { buf, err := e.EncodeBinary(nil, nil) if err != nil { - return nil, fmt.Errorf("failed to encode values[%d]", i) + return nil, errors.Errorf("failed to encode values[%d]", i) } dr.Values[i] = buf } else { - return nil, fmt.Errorf("values[%d] does not implement BinaryEncoder", i) + return nil, errors.Errorf("values[%d] does not implement BinaryEncoder", i) } default: return nil, errors.New("unknown FormatCode") diff --git a/pgproto3/authentication.go b/pgproto3/authentication.go index c04ee448..77750b86 100644 --- a/pgproto3/authentication.go +++ b/pgproto3/authentication.go @@ -2,9 +2,9 @@ package pgproto3 import ( "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) const ( @@ -31,7 +31,7 @@ func (dst *Authentication) Decode(src []byte) error { case AuthTypeMD5Password: copy(dst.Salt[:], src[4:8]) default: - return fmt.Errorf("unknown authentication type: %d", dst.Type) + return errors.Errorf("unknown authentication type: %d", dst.Type) } return nil diff --git a/pgproto3/backend.go b/pgproto3/backend.go index bf96ba95..9a7ef342 100644 --- a/pgproto3/backend.go +++ b/pgproto3/backend.go @@ -2,10 +2,10 @@ package pgproto3 import ( "encoding/binary" - "fmt" "io" "github.com/jackc/pgx/chunkreader" + "github.com/pkg/errors" ) type Backend struct { @@ -88,7 +88,7 @@ func (b *Backend) Receive() (FrontendMessage, error) { case 'X': msg = &b.terminate default: - return nil, fmt.Errorf("unknown message type: %c", msgType) + return nil, errors.Errorf("unknown message type: %c", msgType) } msgBody, err := b.cr.Next(bodyLen) diff --git a/pgproto3/frontend.go b/pgproto3/frontend.go index 630a5cba..c8ab5f15 100644 --- a/pgproto3/frontend.go +++ b/pgproto3/frontend.go @@ -2,10 +2,10 @@ package pgproto3 import ( "encoding/binary" - "fmt" "io" "github.com/jackc/pgx/chunkreader" + "github.com/pkg/errors" ) type Frontend struct { @@ -100,7 +100,7 @@ func (b *Frontend) Receive() (BackendMessage, error) { case 'Z': msg = &b.readyForQuery default: - return nil, fmt.Errorf("unknown message type: %c", msgType) + return nil, errors.Errorf("unknown message type: %c", msgType) } msgBody, err := b.cr.Next(bodyLen) diff --git a/pgproto3/startup_message.go b/pgproto3/startup_message.go index 4e2df27d..6c5d4f99 100644 --- a/pgproto3/startup_message.go +++ b/pgproto3/startup_message.go @@ -4,9 +4,9 @@ import ( "bytes" "encoding/binary" "encoding/json" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) const ( @@ -23,18 +23,18 @@ func (*StartupMessage) Frontend() {} func (dst *StartupMessage) Decode(src []byte) error { if len(src) < 4 { - return fmt.Errorf("startup message too short") + return errors.Errorf("startup message too short") } dst.ProtocolVersion = binary.BigEndian.Uint32(src) rp := 4 if dst.ProtocolVersion == sslRequestNumber { - return fmt.Errorf("can't handle ssl connection request") + return errors.Errorf("can't handle ssl connection request") } if dst.ProtocolVersion != ProtocolVersionNumber { - return fmt.Errorf("Bad startup message version number. Expected %d, got %d", ProtocolVersionNumber, dst.ProtocolVersion) + return errors.Errorf("Bad startup message version number. Expected %d, got %d", ProtocolVersionNumber, dst.ProtocolVersion) } dst.Parameters = make(map[string]string) @@ -57,7 +57,7 @@ func (dst *StartupMessage) Decode(src []byte) error { if len(src[rp:]) == 1 { if src[rp] != 0 { - return fmt.Errorf("Bad startup message last byte. Expected 0, got %d", src[rp]) + return errors.Errorf("Bad startup message last byte. Expected 0, got %d", src[rp]) } break } diff --git a/pgtype/aclitem.go b/pgtype/aclitem.go index 829eb908..35269e91 100644 --- a/pgtype/aclitem.go +++ b/pgtype/aclitem.go @@ -2,7 +2,8 @@ package pgtype import ( "database/sql/driver" - "fmt" + + "github.com/pkg/errors" ) // ACLItem is used for PostgreSQL's aclitem data type. A sample aclitem @@ -36,7 +37,7 @@ func (dst *ACLItem) Set(src interface{}) error { if originalSrc, ok := underlyingStringType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to ACLItem", value) + return errors.Errorf("cannot convert %v to ACLItem", value) } return nil @@ -69,7 +70,7 @@ func (src *ACLItem) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *ACLItem) DecodeText(ci *ConnInfo, src []byte) error { @@ -109,7 +110,7 @@ func (dst *ACLItem) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/aclitem_array.go b/pgtype/aclitem_array.go index f9215a93..fe0af434 100644 --- a/pgtype/aclitem_array.go +++ b/pgtype/aclitem_array.go @@ -2,7 +2,8 @@ package pgtype import ( "database/sql/driver" - "fmt" + + "github.com/pkg/errors" ) type ACLItemArray struct { @@ -37,7 +38,7 @@ func (dst *ACLItemArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to ACLItem", value) + return errors.Errorf("cannot convert %v to ACLItem", value) } return nil @@ -77,7 +78,7 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *ACLItemArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -188,7 +189,7 @@ func (dst *ACLItemArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/array.go b/pgtype/array.go index e5504455..5b852ed5 100644 --- a/pgtype/array.go +++ b/pgtype/array.go @@ -3,13 +3,13 @@ package pgtype import ( "bytes" "encoding/binary" - "fmt" "io" "strconv" "strings" "unicode" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) // Information on the internals of PostgreSQL arrays can be found in @@ -29,7 +29,7 @@ type ArrayDimension struct { func (dst *ArrayHeader) DecodeBinary(ci *ConnInfo, src []byte) (int, error) { if len(src) < 12 { - return 0, fmt.Errorf("array header too short: %d", len(src)) + return 0, errors.Errorf("array header too short: %d", len(src)) } rp := 0 @@ -47,7 +47,7 @@ func (dst *ArrayHeader) DecodeBinary(ci *ConnInfo, src []byte) (int, error) { dst.Dimensions = make([]ArrayDimension, numDims) } if len(src) < 12+numDims*8 { - return 0, fmt.Errorf("array header too short for %d dimensions: %d", numDims, len(src)) + return 0, errors.Errorf("array header too short for %d dimensions: %d", numDims, len(src)) } for i := range dst.Dimensions { dst.Dimensions[i].Length = int32(binary.BigEndian.Uint32(src[rp:])) @@ -93,7 +93,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { r, _, err := buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } var explicitDimensions []ArrayDimension @@ -105,41 +105,41 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { for { r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } if r == '=' { break } else if r != '[' { - return nil, fmt.Errorf("invalid array, expected '[' or '=' got %v", r) + return nil, errors.Errorf("invalid array, expected '[' or '=' got %v", r) } lower, err := arrayParseInteger(buf) if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } if r != ':' { - return nil, fmt.Errorf("invalid array, expected ':' got %v", r) + return nil, errors.Errorf("invalid array, expected ':' got %v", r) } upper, err := arrayParseInteger(buf) if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } if r != ']' { - return nil, fmt.Errorf("invalid array, expected ']' got %v", r) + return nil, errors.Errorf("invalid array, expected ']' got %v", r) } explicitDimensions = append(explicitDimensions, ArrayDimension{LowerBound: lower, Length: upper - lower + 1}) @@ -147,12 +147,12 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } } if r != '{' { - return nil, fmt.Errorf("invalid array, expected '{': %v", err) + return nil, errors.Errorf("invalid array, expected '{': %v", err) } implicitDimensions := []ArrayDimension{{LowerBound: 1, Length: 0}} @@ -161,7 +161,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { for { r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } if r == '{' { @@ -178,7 +178,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { for { r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid array: %v", err) + return nil, errors.Errorf("invalid array: %v", err) } switch r { @@ -197,7 +197,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { buf.UnreadRune() value, err := arrayParseValue(buf) if err != nil { - return nil, fmt.Errorf("invalid array value: %v", err) + return nil, errors.Errorf("invalid array value: %v", err) } if currentDim == counterDim { implicitDimensions[currentDim].Length++ @@ -213,7 +213,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { skipWhitespace(buf) if buf.Len() > 0 { - return nil, fmt.Errorf("unexpected trailing data: %v", buf.String()) + return nil, errors.Errorf("unexpected trailing data: %v", buf.String()) } if len(dst.Elements) == 0 { diff --git a/pgtype/bool.go b/pgtype/bool.go index 7c66a534..3a3eef48 100644 --- a/pgtype/bool.go +++ b/pgtype/bool.go @@ -2,8 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "strconv" + + "github.com/pkg/errors" ) type Bool struct { @@ -25,7 +26,7 @@ func (dst *Bool) Set(src interface{}) error { if originalSrc, ok := underlyingBoolType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Bool", value) + return errors.Errorf("cannot convert %v to Bool", value) } return nil @@ -58,7 +59,7 @@ func (src *Bool) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Bool) DecodeText(ci *ConnInfo, src []byte) error { @@ -68,7 +69,7 @@ func (dst *Bool) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) != 1 { - return fmt.Errorf("invalid length for bool: %v", len(src)) + return errors.Errorf("invalid length for bool: %v", len(src)) } *dst = Bool{Bool: src[0] == 't', Status: Present} @@ -82,7 +83,7 @@ func (dst *Bool) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 1 { - return fmt.Errorf("invalid length for bool: %v", len(src)) + return errors.Errorf("invalid length for bool: %v", len(src)) } *dst = Bool{Bool: src[0] == 1, Status: Present} @@ -142,7 +143,7 @@ func (dst *Bool) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/bool_array.go b/pgtype/bool_array.go index e20a0381..e23c27e5 100644 --- a/pgtype/bool_array.go +++ b/pgtype/bool_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type BoolArray struct { @@ -40,7 +40,7 @@ func (dst *BoolArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Bool", value) + return errors.Errorf("cannot convert %v to Bool", value) } return nil @@ -80,7 +80,7 @@ func (src *BoolArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *BoolArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -233,7 +233,7 @@ func (src *BoolArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("bool"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "bool") + return nil, errors.Errorf("unable to find oid for type name %v", "bool") } for i := range src.Elements { @@ -277,7 +277,7 @@ func (dst *BoolArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/box.go b/pgtype/box.go index 2d098058..83df0499 100644 --- a/pgtype/box.go +++ b/pgtype/box.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Box struct { @@ -17,7 +18,7 @@ type Box struct { } func (dst *Box) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Box", src) + return errors.Errorf("cannot convert %v to Box", src) } func (dst *Box) Get() interface{} { @@ -32,7 +33,7 @@ func (dst *Box) Get() interface{} { } func (src *Box) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Box) DecodeText(ci *ConnInfo, src []byte) error { @@ -42,7 +43,7 @@ func (dst *Box) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 11 { - return fmt.Errorf("invalid length for Box: %v", len(src)) + return errors.Errorf("invalid length for Box: %v", len(src)) } str := string(src[1:]) @@ -89,7 +90,7 @@ func (dst *Box) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 32 { - return fmt.Errorf("invalid length for Box: %v", len(src)) + return errors.Errorf("invalid length for Box: %v", len(src)) } x1 := binary.BigEndian.Uint64(src) @@ -152,7 +153,7 @@ func (dst *Box) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/bytea.go b/pgtype/bytea.go index 2ddac7da..c7117f48 100644 --- a/pgtype/bytea.go +++ b/pgtype/bytea.go @@ -3,7 +3,8 @@ package pgtype import ( "database/sql/driver" "encoding/hex" - "fmt" + + "github.com/pkg/errors" ) type Bytea struct { @@ -28,7 +29,7 @@ func (dst *Bytea) Set(src interface{}) error { if originalSrc, ok := underlyingBytesType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Bytea", value) + return errors.Errorf("cannot convert %v to Bytea", value) } return nil @@ -63,7 +64,7 @@ func (src *Bytea) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } // DecodeText only supports the hex format. This has been the default since @@ -75,7 +76,7 @@ func (dst *Bytea) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 2 || src[0] != '\\' || src[1] != 'x' { - return fmt.Errorf("invalid hex format") + return errors.Errorf("invalid hex format") } buf := make([]byte, (len(src)-2)/2) @@ -139,7 +140,7 @@ func (dst *Bytea) Scan(src interface{}) error { return nil } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/bytea_array.go b/pgtype/bytea_array.go index 0d381693..f2842179 100644 --- a/pgtype/bytea_array.go +++ b/pgtype/bytea_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type ByteaArray struct { @@ -40,7 +40,7 @@ func (dst *ByteaArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Bytea", value) + return errors.Errorf("cannot convert %v to Bytea", value) } return nil @@ -80,7 +80,7 @@ func (src *ByteaArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *ByteaArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -233,7 +233,7 @@ func (src *ByteaArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("bytea"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "bytea") + return nil, errors.Errorf("unable to find oid for type name %v", "bytea") } for i := range src.Elements { @@ -277,7 +277,7 @@ func (dst *ByteaArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/cidr_array.go b/pgtype/cidr_array.go index 9b7b50fa..2373da46 100644 --- a/pgtype/cidr_array.go +++ b/pgtype/cidr_array.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "net" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type CIDRArray struct { @@ -60,7 +60,7 @@ func (dst *CIDRArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to CIDR", value) + return errors.Errorf("cannot convert %v to CIDR", value) } return nil @@ -109,7 +109,7 @@ func (src *CIDRArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *CIDRArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -262,7 +262,7 @@ func (src *CIDRArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("cidr"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "cidr") + return nil, errors.Errorf("unable to find oid for type name %v", "cidr") } for i := range src.Elements { @@ -306,7 +306,7 @@ func (dst *CIDRArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/circle.go b/pgtype/circle.go index 8626a99d..97ecbf31 100644 --- a/pgtype/circle.go +++ b/pgtype/circle.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Circle struct { @@ -18,7 +19,7 @@ type Circle struct { } func (dst *Circle) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Circle", src) + return errors.Errorf("cannot convert %v to Circle", src) } func (dst *Circle) Get() interface{} { @@ -33,7 +34,7 @@ func (dst *Circle) Get() interface{} { } func (src *Circle) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Circle) DecodeText(ci *ConnInfo, src []byte) error { @@ -43,7 +44,7 @@ func (dst *Circle) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 9 { - return fmt.Errorf("invalid length for Circle: %v", len(src)) + return errors.Errorf("invalid length for Circle: %v", len(src)) } str := string(src[2:]) @@ -79,7 +80,7 @@ func (dst *Circle) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 24 { - return fmt.Errorf("invalid length for Circle: %v", len(src)) + return errors.Errorf("invalid length for Circle: %v", len(src)) } x := binary.BigEndian.Uint64(src) @@ -136,7 +137,7 @@ func (dst *Circle) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/convert.go b/pgtype/convert.go index 2b406426..5dfb738e 100644 --- a/pgtype/convert.go +++ b/pgtype/convert.go @@ -1,10 +1,11 @@ package pgtype import ( - "fmt" "math" "reflect" "time" + + "github.com/pkg/errors" ) const maxUint = ^uint(0) @@ -189,70 +190,70 @@ func int64AssignTo(srcVal int64, srcStatus Status, dst interface{}) error { switch v := dst.(type) { case *int: if srcVal < int64(minInt) { - return fmt.Errorf("%d is less than minimum value for int", srcVal) + return errors.Errorf("%d is less than minimum value for int", srcVal) } else if srcVal > int64(maxInt) { - return fmt.Errorf("%d is greater than maximum value for int", srcVal) + return errors.Errorf("%d is greater than maximum value for int", srcVal) } *v = int(srcVal) case *int8: if srcVal < math.MinInt8 { - return fmt.Errorf("%d is less than minimum value for int8", srcVal) + return errors.Errorf("%d is less than minimum value for int8", srcVal) } else if srcVal > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for int8", srcVal) + return errors.Errorf("%d is greater than maximum value for int8", srcVal) } *v = int8(srcVal) case *int16: if srcVal < math.MinInt16 { - return fmt.Errorf("%d is less than minimum value for int16", srcVal) + return errors.Errorf("%d is less than minimum value for int16", srcVal) } else if srcVal > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for int16", srcVal) + return errors.Errorf("%d is greater than maximum value for int16", srcVal) } *v = int16(srcVal) case *int32: if srcVal < math.MinInt32 { - return fmt.Errorf("%d is less than minimum value for int32", srcVal) + return errors.Errorf("%d is less than minimum value for int32", srcVal) } else if srcVal > math.MaxInt32 { - return fmt.Errorf("%d is greater than maximum value for int32", srcVal) + return errors.Errorf("%d is greater than maximum value for int32", srcVal) } *v = int32(srcVal) case *int64: if srcVal < math.MinInt64 { - return fmt.Errorf("%d is less than minimum value for int64", srcVal) + return errors.Errorf("%d is less than minimum value for int64", srcVal) } else if srcVal > math.MaxInt64 { - return fmt.Errorf("%d is greater than maximum value for int64", srcVal) + return errors.Errorf("%d is greater than maximum value for int64", srcVal) } *v = int64(srcVal) case *uint: if srcVal < 0 { - return fmt.Errorf("%d is less than zero for uint", srcVal) + return errors.Errorf("%d is less than zero for uint", srcVal) } else if uint64(srcVal) > uint64(maxUint) { - return fmt.Errorf("%d is greater than maximum value for uint", srcVal) + return errors.Errorf("%d is greater than maximum value for uint", srcVal) } *v = uint(srcVal) case *uint8: if srcVal < 0 { - return fmt.Errorf("%d is less than zero for uint8", srcVal) + return errors.Errorf("%d is less than zero for uint8", srcVal) } else if srcVal > math.MaxUint8 { - return fmt.Errorf("%d is greater than maximum value for uint8", srcVal) + return errors.Errorf("%d is greater than maximum value for uint8", srcVal) } *v = uint8(srcVal) case *uint16: if srcVal < 0 { - return fmt.Errorf("%d is less than zero for uint32", srcVal) + return errors.Errorf("%d is less than zero for uint32", srcVal) } else if srcVal > math.MaxUint16 { - return fmt.Errorf("%d is greater than maximum value for uint16", srcVal) + return errors.Errorf("%d is greater than maximum value for uint16", srcVal) } *v = uint16(srcVal) case *uint32: if srcVal < 0 { - return fmt.Errorf("%d is less than zero for uint32", srcVal) + return errors.Errorf("%d is less than zero for uint32", srcVal) } else if srcVal > math.MaxUint32 { - return fmt.Errorf("%d is greater than maximum value for uint32", srcVal) + return errors.Errorf("%d is greater than maximum value for uint32", srcVal) } *v = uint32(srcVal) case *uint64: if srcVal < 0 { - return fmt.Errorf("%d is less than zero for uint64", srcVal) + return errors.Errorf("%d is less than zero for uint64", srcVal) } *v = uint64(srcVal) default: @@ -268,22 +269,22 @@ func int64AssignTo(srcVal int64, srcStatus Status, dst interface{}) error { return int64AssignTo(srcVal, srcStatus, el.Interface()) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: if el.OverflowInt(int64(srcVal)) { - return fmt.Errorf("cannot put %d into %T", srcVal, dst) + return errors.Errorf("cannot put %d into %T", srcVal, dst) } el.SetInt(int64(srcVal)) return nil case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: if srcVal < 0 { - return fmt.Errorf("%d is less than zero for %T", srcVal, dst) + return errors.Errorf("%d is less than zero for %T", srcVal, dst) } if el.OverflowUint(uint64(srcVal)) { - return fmt.Errorf("cannot put %d into %T", srcVal, dst) + return errors.Errorf("cannot put %d into %T", srcVal, dst) } el.SetUint(uint64(srcVal)) return nil } } - return fmt.Errorf("cannot assign %v into %T", srcVal, dst) + return errors.Errorf("cannot assign %v into %T", srcVal, dst) } return nil } @@ -297,7 +298,7 @@ func int64AssignTo(srcVal int64, srcStatus Status, dst interface{}) error { } } - return fmt.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) + return errors.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) } func float64AssignTo(srcVal float64, srcStatus Status, dst interface{}) error { @@ -325,7 +326,7 @@ func float64AssignTo(srcVal float64, srcStatus Status, dst interface{}) error { } } } - return fmt.Errorf("cannot assign %v into %T", srcVal, dst) + return errors.Errorf("cannot assign %v into %T", srcVal, dst) } return nil } @@ -339,7 +340,7 @@ func float64AssignTo(srcVal float64, srcStatus Status, dst interface{}) error { } } - return fmt.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) + return errors.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) } func NullAssignTo(dst interface{}) error { @@ -347,7 +348,7 @@ func NullAssignTo(dst interface{}) error { // AssignTo dst must always be a pointer if dstPtr.Kind() != reflect.Ptr { - return fmt.Errorf("cannot assign NULL to %T", dst) + return errors.Errorf("cannot assign NULL to %T", dst) } dstVal := dstPtr.Elem() @@ -358,7 +359,7 @@ func NullAssignTo(dst interface{}) error { return nil } - return fmt.Errorf("cannot assign NULL to %T", dst) + return errors.Errorf("cannot assign NULL to %T", dst) } var kindTypes map[reflect.Kind]reflect.Type diff --git a/pgtype/database_sql.go b/pgtype/database_sql.go index 9d1cf822..969536dd 100644 --- a/pgtype/database_sql.go +++ b/pgtype/database_sql.go @@ -2,7 +2,8 @@ package pgtype import ( "database/sql/driver" - "errors" + + "github.com/pkg/errors" ) func DatabaseSQLValue(ci *ConnInfo, src Value) (interface{}, error) { diff --git a/pgtype/date.go b/pgtype/date.go index 8e049254..f1c0d8bd 100644 --- a/pgtype/date.go +++ b/pgtype/date.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "time" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Date struct { @@ -33,7 +33,7 @@ func (dst *Date) Set(src interface{}) error { if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Date", value) + return errors.Errorf("cannot convert %v to Date", value) } return nil @@ -59,7 +59,7 @@ func (src *Date) AssignTo(dst interface{}) error { switch v := dst.(type) { case *time.Time: if src.InfinityModifier != None { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } *v = src.Time return nil @@ -72,7 +72,7 @@ func (src *Date) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Date) DecodeText(ci *ConnInfo, src []byte) error { @@ -106,7 +106,7 @@ func (dst *Date) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 4 { - return fmt.Errorf("invalid length for date: %v", len(src)) + return errors.Errorf("invalid length for date: %v", len(src)) } dayOffset := int32(binary.BigEndian.Uint32(src)) @@ -190,7 +190,7 @@ func (dst *Date) Scan(src interface{}) error { return nil } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/date_array.go b/pgtype/date_array.go index ef91cf3e..383945e7 100644 --- a/pgtype/date_array.go +++ b/pgtype/date_array.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "time" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type DateArray struct { @@ -41,7 +41,7 @@ func (dst *DateArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Date", value) + return errors.Errorf("cannot convert %v to Date", value) } return nil @@ -81,7 +81,7 @@ func (src *DateArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *DateArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -234,7 +234,7 @@ func (src *DateArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("date"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "date") + return nil, errors.Errorf("unable to find oid for type name %v", "date") } for i := range src.Elements { @@ -278,7 +278,7 @@ func (dst *DateArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/daterange.go b/pgtype/daterange.go index bbe7b17a..47cd7e46 100644 --- a/pgtype/daterange.go +++ b/pgtype/daterange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Daterange struct { @@ -16,7 +16,7 @@ type Daterange struct { } func (dst *Daterange) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Daterange", src) + return errors.Errorf("cannot convert %v to Daterange", src) } func (dst *Daterange) Get() interface{} { @@ -31,7 +31,7 @@ func (dst *Daterange) Get() interface{} { } func (src *Daterange) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Daterange) DecodeText(ci *ConnInfo, src []byte) error { @@ -120,7 +120,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) + return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -130,7 +130,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -141,7 +141,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -151,7 +151,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) + return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -175,7 +175,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) + return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -185,7 +185,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) + return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -201,7 +201,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -216,7 +216,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -241,7 +241,7 @@ func (dst *Daterange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/ext/satori-uuid/uuid.go b/pgtype/ext/satori-uuid/uuid.go index b7b776f9..78a90035 100644 --- a/pgtype/ext/satori-uuid/uuid.go +++ b/pgtype/ext/satori-uuid/uuid.go @@ -2,8 +2,8 @@ package uuid import ( "database/sql/driver" - "errors" - "fmt" + + "github.com/pkg/errors" "github.com/jackc/pgx/pgtype" uuid "github.com/satori/go.uuid" @@ -24,7 +24,7 @@ func (dst *UUID) Set(src interface{}) error { *dst = UUID{UUID: uuid.UUID(value), Status: pgtype.Present} case []byte: if len(value) != 16 { - return fmt.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) + return errors.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) } *dst = UUID{Status: pgtype.Present} copy(dst.UUID[:], value) @@ -38,7 +38,7 @@ func (dst *UUID) Set(src interface{}) error { // If all else fails see if pgtype.UUID can handle it. If so, translate through that. pgUUID := &pgtype.UUID{} if err := pgUUID.Set(value); err != nil { - return fmt.Errorf("cannot convert %v to UUID", value) + return errors.Errorf("cannot convert %v to UUID", value) } *dst = UUID{UUID: uuid.UUID(pgUUID.Bytes), Status: pgUUID.Status} @@ -83,7 +83,7 @@ func (src *UUID) AssignTo(dst interface{}) error { return pgtype.NullAssignTo(dst) } - return fmt.Errorf("cannot assign %v into %T", src, dst) + return errors.Errorf("cannot assign %v into %T", src, dst) } func (dst *UUID) DecodeText(ci *pgtype.ConnInfo, src []byte) error { @@ -108,7 +108,7 @@ func (dst *UUID) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error { } if len(src) != 16 { - return fmt.Errorf("invalid length for UUID: %v", len(src)) + return errors.Errorf("invalid length for UUID: %v", len(src)) } *dst = UUID{Status: pgtype.Present} @@ -152,7 +152,7 @@ func (dst *UUID) Scan(src interface{}) error { return dst.DecodeText(nil, src) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/ext/shopspring-numeric/decimal.go b/pgtype/ext/shopspring-numeric/decimal.go index 277f3709..507a93dc 100644 --- a/pgtype/ext/shopspring-numeric/decimal.go +++ b/pgtype/ext/shopspring-numeric/decimal.go @@ -2,10 +2,10 @@ package numeric import ( "database/sql/driver" - "errors" - "fmt" "strconv" + "github.com/pkg/errors" + "github.com/jackc/pgx/pgtype" "github.com/shopspring/decimal" ) @@ -70,17 +70,17 @@ func (dst *Numeric) Set(src interface{}) error { // If all else fails see if pgtype.Numeric can handle it. If so, translate through that. num := &pgtype.Numeric{} if err := num.Set(value); err != nil { - return fmt.Errorf("cannot convert %v to Numeric", value) + return errors.Errorf("cannot convert %v to Numeric", value) } buf, err := num.EncodeText(nil, nil) if err != nil { - return fmt.Errorf("cannot convert %v to Numeric", value) + return errors.Errorf("cannot convert %v to Numeric", value) } dec, err := decimal.NewFromString(string(buf)) if err != nil { - return fmt.Errorf("cannot convert %v to Numeric", value) + return errors.Errorf("cannot convert %v to Numeric", value) } *dst = Numeric{Decimal: dec, Status: pgtype.Present} } @@ -113,92 +113,92 @@ func (src *Numeric) AssignTo(dst interface{}) error { *v = f case *int: if src.Decimal.Exponent() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, strconv.IntSize) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = int(n) case *int8: if src.Decimal.Exponent() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 8) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = int8(n) case *int16: if src.Decimal.Exponent() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 16) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = int16(n) case *int32: if src.Decimal.Exponent() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 32) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = int32(n) case *int64: if src.Decimal.Exponent() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 64) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = int64(n) case *uint: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, strconv.IntSize) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = uint(n) case *uint8: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 8) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = uint8(n) case *uint16: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 16) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = uint16(n) case *uint32: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 32) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = uint32(n) case *uint64: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 64) if err != nil { - return fmt.Errorf("cannot convert %v to %T", dst, *v) + return errors.Errorf("cannot convert %v to %T", dst, *v) } *v = uint64(n) default: @@ -301,7 +301,7 @@ func (dst *Numeric) Scan(src interface{}) error { return dst.DecodeText(nil, src) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/float4.go b/pgtype/float4.go index b24654b6..2207594a 100644 --- a/pgtype/float4.go +++ b/pgtype/float4.go @@ -3,11 +3,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "math" "strconv" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Float4 struct { @@ -39,42 +39,42 @@ func (dst *Float4) Set(src interface{}) error { if int32(f32) == value { *dst = Float4{Float: f32, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float32", value) + return errors.Errorf("%v cannot be exactly represented as float32", value) } case uint32: f32 := float32(value) if uint32(f32) == value { *dst = Float4{Float: f32, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float32", value) + return errors.Errorf("%v cannot be exactly represented as float32", value) } case int64: f32 := float32(value) if int64(f32) == value { *dst = Float4{Float: f32, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float32", value) + return errors.Errorf("%v cannot be exactly represented as float32", value) } case uint64: f32 := float32(value) if uint64(f32) == value { *dst = Float4{Float: f32, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float32", value) + return errors.Errorf("%v cannot be exactly represented as float32", value) } case int: f32 := float32(value) if int(f32) == value { *dst = Float4{Float: f32, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float32", value) + return errors.Errorf("%v cannot be exactly represented as float32", value) } case uint: f32 := float32(value) if uint(f32) == value { *dst = Float4{Float: f32, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float32", value) + return errors.Errorf("%v cannot be exactly represented as float32", value) } case string: num, err := strconv.ParseFloat(value, 32) @@ -86,7 +86,7 @@ func (dst *Float4) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Float8", value) + return errors.Errorf("cannot convert %v to Float8", value) } return nil @@ -129,7 +129,7 @@ func (dst *Float4) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 4 { - return fmt.Errorf("invalid length for float4: %v", len(src)) + return errors.Errorf("invalid length for float4: %v", len(src)) } n := int32(binary.BigEndian.Uint32(src)) @@ -181,7 +181,7 @@ func (dst *Float4) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/float4_array.go b/pgtype/float4_array.go index a35657b0..6499064b 100644 --- a/pgtype/float4_array.go +++ b/pgtype/float4_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Float4Array struct { @@ -40,7 +40,7 @@ func (dst *Float4Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Float4", value) + return errors.Errorf("cannot convert %v to Float4", value) } return nil @@ -80,7 +80,7 @@ func (src *Float4Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Float4Array) DecodeText(ci *ConnInfo, src []byte) error { @@ -233,7 +233,7 @@ func (src *Float4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("float4"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "float4") + return nil, errors.Errorf("unable to find oid for type name %v", "float4") } for i := range src.Elements { @@ -277,7 +277,7 @@ func (dst *Float4Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/float8.go b/pgtype/float8.go index c3ecdcc2..dd34f541 100644 --- a/pgtype/float8.go +++ b/pgtype/float8.go @@ -3,11 +3,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "math" "strconv" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Float8 struct { @@ -43,28 +43,28 @@ func (dst *Float8) Set(src interface{}) error { if int64(f64) == value { *dst = Float8{Float: f64, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float64", value) + return errors.Errorf("%v cannot be exactly represented as float64", value) } case uint64: f64 := float64(value) if uint64(f64) == value { *dst = Float8{Float: f64, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float64", value) + return errors.Errorf("%v cannot be exactly represented as float64", value) } case int: f64 := float64(value) if int(f64) == value { *dst = Float8{Float: f64, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float64", value) + return errors.Errorf("%v cannot be exactly represented as float64", value) } case uint: f64 := float64(value) if uint(f64) == value { *dst = Float8{Float: f64, Status: Present} } else { - return fmt.Errorf("%v cannot be exactly represented as float64", value) + return errors.Errorf("%v cannot be exactly represented as float64", value) } case string: num, err := strconv.ParseFloat(value, 64) @@ -76,7 +76,7 @@ func (dst *Float8) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Float8", value) + return errors.Errorf("cannot convert %v to Float8", value) } return nil @@ -119,7 +119,7 @@ func (dst *Float8) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return fmt.Errorf("invalid length for float4: %v", len(src)) + return errors.Errorf("invalid length for float4: %v", len(src)) } n := int64(binary.BigEndian.Uint64(src)) @@ -171,7 +171,7 @@ func (dst *Float8) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/float8_array.go b/pgtype/float8_array.go index 486e3a4e..27b24836 100644 --- a/pgtype/float8_array.go +++ b/pgtype/float8_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Float8Array struct { @@ -40,7 +40,7 @@ func (dst *Float8Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Float8", value) + return errors.Errorf("cannot convert %v to Float8", value) } return nil @@ -80,7 +80,7 @@ func (src *Float8Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Float8Array) DecodeText(ci *ConnInfo, src []byte) error { @@ -233,7 +233,7 @@ func (src *Float8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("float8"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "float8") + return nil, errors.Errorf("unable to find oid for type name %v", "float8") } for i := range src.Elements { @@ -277,7 +277,7 @@ func (dst *Float8Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/hstore.go b/pgtype/hstore.go index 09506242..347446ae 100644 --- a/pgtype/hstore.go +++ b/pgtype/hstore.go @@ -4,12 +4,12 @@ import ( "bytes" "database/sql/driver" "encoding/binary" - "errors" - "fmt" "strings" "unicode" "unicode/utf8" + "github.com/pkg/errors" + "github.com/jackc/pgx/pgio" ) @@ -34,7 +34,7 @@ func (dst *Hstore) Set(src interface{}) error { } *dst = Hstore{Map: m, Status: Present} default: - return fmt.Errorf("cannot convert %v to Hstore", src) + return errors.Errorf("cannot convert %v to Hstore", src) } return nil @@ -59,7 +59,7 @@ func (src *Hstore) AssignTo(dst interface{}) error { *v = make(map[string]string, len(src.Map)) for k, val := range src.Map { if val.Status != Present { - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } (*v)[k] = val.String } @@ -73,7 +73,7 @@ func (src *Hstore) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Hstore) DecodeText(ci *ConnInfo, src []byte) error { @@ -105,7 +105,7 @@ func (dst *Hstore) DecodeBinary(ci *ConnInfo, src []byte) error { rp := 0 if len(src[rp:]) < 4 { - return fmt.Errorf("hstore incomplete %v", src) + return errors.Errorf("hstore incomplete %v", src) } pairCount := int(int32(binary.BigEndian.Uint32(src[rp:]))) rp += 4 @@ -114,19 +114,19 @@ func (dst *Hstore) DecodeBinary(ci *ConnInfo, src []byte) error { for i := 0; i < pairCount; i++ { if len(src[rp:]) < 4 { - return fmt.Errorf("hstore incomplete %v", src) + return errors.Errorf("hstore incomplete %v", src) } keyLen := int(int32(binary.BigEndian.Uint32(src[rp:]))) rp += 4 if len(src[rp:]) < keyLen { - return fmt.Errorf("hstore incomplete %v", src) + return errors.Errorf("hstore incomplete %v", src) } key := string(src[rp : rp+keyLen]) rp += keyLen if len(src[rp:]) < 4 { - return fmt.Errorf("hstore incomplete %v", src) + return errors.Errorf("hstore incomplete %v", src) } valueLen := int(int32(binary.BigEndian.Uint32(src[rp:]))) rp += 4 @@ -333,13 +333,13 @@ func parseHstore(s string) (k []string, v []Text, err error) { case r == 'N': state = hsNul default: - err = fmt.Errorf("Invalid character '%c' after '=>', expecting '\"' or 'NULL'", r) + err = errors.Errorf("Invalid character '%c' after '=>', expecting '\"' or 'NULL'", r) } default: - err = fmt.Errorf("Invalid character after '=', expecting '>'") + err = errors.Errorf("Invalid character after '=', expecting '>'") } } else { - err = fmt.Errorf("Invalid character '%c' after value, expecting '='", r) + err = errors.Errorf("Invalid character '%c' after value, expecting '='", r) } case hsVal: switch r { @@ -376,7 +376,7 @@ func parseHstore(s string) (k []string, v []Text, err error) { values = append(values, Text{Status: Null}) state = hsNext } else { - err = fmt.Errorf("Invalid NULL value: 'N%s'", string(nulBuf)) + err = errors.Errorf("Invalid NULL value: 'N%s'", string(nulBuf)) } case hsNext: if r == ',' { @@ -388,10 +388,10 @@ func parseHstore(s string) (k []string, v []Text, err error) { r, end = p.Consume() state = hsKey default: - err = fmt.Errorf("Invalid character '%c' after ', ', expecting \"", r) + err = errors.Errorf("Invalid character '%c' after ', ', expecting \"", r) } } else { - err = fmt.Errorf("Invalid character '%c' after value, expecting ','", r) + err = errors.Errorf("Invalid character '%c' after value, expecting ','", r) } } @@ -425,7 +425,7 @@ func (dst *Hstore) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/hstore_array.go b/pgtype/hstore_array.go index 3e5a003f..38ce457b 100644 --- a/pgtype/hstore_array.go +++ b/pgtype/hstore_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type HstoreArray struct { @@ -40,7 +40,7 @@ func (dst *HstoreArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Hstore", value) + return errors.Errorf("cannot convert %v to Hstore", value) } return nil @@ -80,7 +80,7 @@ func (src *HstoreArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *HstoreArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -233,7 +233,7 @@ func (src *HstoreArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("hstore"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "hstore") + return nil, errors.Errorf("unable to find oid for type name %v", "hstore") } for i := range src.Elements { @@ -277,7 +277,7 @@ func (dst *HstoreArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/inet.go b/pgtype/inet.go index 7aa1df95..01fc0e5b 100644 --- a/pgtype/inet.go +++ b/pgtype/inet.go @@ -2,8 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "net" + + "github.com/pkg/errors" ) // Network address family is dependent on server socket.h value for AF_INET. @@ -45,7 +46,7 @@ func (dst *Inet) Set(src interface{}) error { if originalSrc, ok := underlyingPtrType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Inet", value) + return errors.Errorf("cannot convert %v to Inet", value) } return nil @@ -76,7 +77,7 @@ func (src *Inet) AssignTo(dst interface{}) error { return nil case *net.IP: if oneCount, bitCount := src.IPNet.Mask.Size(); oneCount != bitCount { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } *v = make(net.IP, len(src.IPNet.IP)) copy(*v, src.IPNet.IP) @@ -90,7 +91,7 @@ func (src *Inet) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Inet) DecodeText(ci *ConnInfo, src []byte) error { @@ -128,7 +129,7 @@ func (dst *Inet) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 && len(src) != 20 { - return fmt.Errorf("Received an invalid size for a inet: %d", len(src)) + return errors.Errorf("Received an invalid size for a inet: %d", len(src)) } // ignore family @@ -173,7 +174,7 @@ func (src *Inet) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case net.IPv6len: family = defaultAFInet6 default: - return nil, fmt.Errorf("Unexpected IP length: %v", len(src.IPNet.IP)) + return nil, errors.Errorf("Unexpected IP length: %v", len(src.IPNet.IP)) } buf = append(buf, family) @@ -205,7 +206,7 @@ func (dst *Inet) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/inet_array.go b/pgtype/inet_array.go index 57123c1c..3ece23eb 100644 --- a/pgtype/inet_array.go +++ b/pgtype/inet_array.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "net" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type InetArray struct { @@ -60,7 +60,7 @@ func (dst *InetArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Inet", value) + return errors.Errorf("cannot convert %v to Inet", value) } return nil @@ -109,7 +109,7 @@ func (src *InetArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *InetArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -262,7 +262,7 @@ func (src *InetArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("inet"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "inet") + return nil, errors.Errorf("unable to find oid for type name %v", "inet") } for i := range src.Elements { @@ -306,7 +306,7 @@ func (dst *InetArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int2.go b/pgtype/int2.go index a58c3355..45bce93c 100644 --- a/pgtype/int2.go +++ b/pgtype/int2.go @@ -3,11 +3,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "math" "strconv" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int2 struct { @@ -30,46 +30,46 @@ func (dst *Int2) Set(src interface{}) error { *dst = Int2{Int: int16(value), Status: Present} case uint16: if value > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case int32: if value < math.MinInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } if value > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case uint32: if value > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case int64: if value < math.MinInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } if value > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case uint64: if value > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case int: if value < math.MinInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } if value > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case uint: if value > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", value) + return errors.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case string: @@ -82,7 +82,7 @@ func (dst *Int2) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Int2", value) + return errors.Errorf("cannot convert %v to Int2", value) } return nil @@ -125,7 +125,7 @@ func (dst *Int2) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 2 { - return fmt.Errorf("invalid length for int2: %v", len(src)) + return errors.Errorf("invalid length for int2: %v", len(src)) } n := int16(binary.BigEndian.Uint16(src)) @@ -165,10 +165,10 @@ func (dst *Int2) Scan(src interface{}) error { switch src := src.(type) { case int64: if src < math.MinInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", src) + return errors.Errorf("%d is greater than maximum value for Int2", src) } if src > math.MaxInt16 { - return fmt.Errorf("%d is greater than maximum value for Int2", src) + return errors.Errorf("%d is greater than maximum value for Int2", src) } *dst = Int2{Int: int16(src), Status: Present} return nil @@ -180,7 +180,7 @@ func (dst *Int2) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int2_array.go b/pgtype/int2_array.go index e4993104..e939411b 100644 --- a/pgtype/int2_array.go +++ b/pgtype/int2_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int2Array struct { @@ -59,7 +59,7 @@ func (dst *Int2Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Int2", value) + return errors.Errorf("cannot convert %v to Int2", value) } return nil @@ -108,7 +108,7 @@ func (src *Int2Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Int2Array) DecodeText(ci *ConnInfo, src []byte) error { @@ -261,7 +261,7 @@ func (src *Int2Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("int2"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "int2") + return nil, errors.Errorf("unable to find oid for type name %v", "int2") } for i := range src.Elements { @@ -305,7 +305,7 @@ func (dst *Int2Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int4.go b/pgtype/int4.go index 6f95013b..a3499fef 100644 --- a/pgtype/int4.go +++ b/pgtype/int4.go @@ -3,11 +3,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "math" "strconv" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int4 struct { @@ -34,33 +34,33 @@ func (dst *Int4) Set(src interface{}) error { *dst = Int4{Int: int32(value), Status: Present} case uint32: if value > math.MaxInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", value) + return errors.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case int64: if value < math.MinInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", value) + return errors.Errorf("%d is greater than maximum value for Int4", value) } if value > math.MaxInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", value) + return errors.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case uint64: if value > math.MaxInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", value) + return errors.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case int: if value < math.MinInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", value) + return errors.Errorf("%d is greater than maximum value for Int4", value) } if value > math.MaxInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", value) + return errors.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case uint: if value > math.MaxInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", value) + return errors.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case string: @@ -73,7 +73,7 @@ func (dst *Int4) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Int4", value) + return errors.Errorf("cannot convert %v to Int4", value) } return nil @@ -116,7 +116,7 @@ func (dst *Int4) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 4 { - return fmt.Errorf("invalid length for int4: %v", len(src)) + return errors.Errorf("invalid length for int4: %v", len(src)) } n := int32(binary.BigEndian.Uint32(src)) @@ -156,10 +156,10 @@ func (dst *Int4) Scan(src interface{}) error { switch src := src.(type) { case int64: if src < math.MinInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", src) + return errors.Errorf("%d is greater than maximum value for Int4", src) } if src > math.MaxInt32 { - return fmt.Errorf("%d is greater than maximum value for Int4", src) + return errors.Errorf("%d is greater than maximum value for Int4", src) } *dst = Int4{Int: int32(src), Status: Present} return nil @@ -171,7 +171,7 @@ func (dst *Int4) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int4_array.go b/pgtype/int4_array.go index 6bc06e86..1a907d2e 100644 --- a/pgtype/int4_array.go +++ b/pgtype/int4_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int4Array struct { @@ -59,7 +59,7 @@ func (dst *Int4Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Int4", value) + return errors.Errorf("cannot convert %v to Int4", value) } return nil @@ -108,7 +108,7 @@ func (src *Int4Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Int4Array) DecodeText(ci *ConnInfo, src []byte) error { @@ -261,7 +261,7 @@ func (src *Int4Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("int4"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "int4") + return nil, errors.Errorf("unable to find oid for type name %v", "int4") } for i := range src.Elements { @@ -305,7 +305,7 @@ func (dst *Int4Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int4range.go b/pgtype/int4range.go index 4f27ff0d..95ad1521 100644 --- a/pgtype/int4range.go +++ b/pgtype/int4range.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int4range struct { @@ -16,7 +16,7 @@ type Int4range struct { } func (dst *Int4range) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Int4range", src) + return errors.Errorf("cannot convert %v to Int4range", src) } func (dst *Int4range) Get() interface{} { @@ -31,7 +31,7 @@ func (dst *Int4range) Get() interface{} { } func (src *Int4range) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Int4range) DecodeText(ci *ConnInfo, src []byte) error { @@ -120,7 +120,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) + return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -130,7 +130,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -141,7 +141,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -151,7 +151,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) + return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -175,7 +175,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) + return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -185,7 +185,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) + return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -201,7 +201,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -216,7 +216,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -241,7 +241,7 @@ func (dst *Int4range) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int8.go b/pgtype/int8.go index 939c0554..d671eda7 100644 --- a/pgtype/int8.go +++ b/pgtype/int8.go @@ -3,11 +3,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "math" "strconv" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int8 struct { @@ -38,20 +38,20 @@ func (dst *Int8) Set(src interface{}) error { *dst = Int8{Int: int64(value), Status: Present} case uint64: if value > math.MaxInt64 { - return fmt.Errorf("%d is greater than maximum value for Int8", value) + return errors.Errorf("%d is greater than maximum value for Int8", value) } *dst = Int8{Int: int64(value), Status: Present} case int: if int64(value) < math.MinInt64 { - return fmt.Errorf("%d is greater than maximum value for Int8", value) + return errors.Errorf("%d is greater than maximum value for Int8", value) } if int64(value) > math.MaxInt64 { - return fmt.Errorf("%d is greater than maximum value for Int8", value) + return errors.Errorf("%d is greater than maximum value for Int8", value) } *dst = Int8{Int: int64(value), Status: Present} case uint: if uint64(value) > math.MaxInt64 { - return fmt.Errorf("%d is greater than maximum value for Int8", value) + return errors.Errorf("%d is greater than maximum value for Int8", value) } *dst = Int8{Int: int64(value), Status: Present} case string: @@ -64,7 +64,7 @@ func (dst *Int8) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Int8", value) + return errors.Errorf("cannot convert %v to Int8", value) } return nil @@ -107,7 +107,7 @@ func (dst *Int8) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return fmt.Errorf("invalid length for int8: %v", len(src)) + return errors.Errorf("invalid length for int8: %v", len(src)) } n := int64(binary.BigEndian.Uint64(src)) @@ -157,7 +157,7 @@ func (dst *Int8) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int8_array.go b/pgtype/int8_array.go index 4404d22a..4f3ab4dc 100644 --- a/pgtype/int8_array.go +++ b/pgtype/int8_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int8Array struct { @@ -59,7 +59,7 @@ func (dst *Int8Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Int8", value) + return errors.Errorf("cannot convert %v to Int8", value) } return nil @@ -108,7 +108,7 @@ func (src *Int8Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Int8Array) DecodeText(ci *ConnInfo, src []byte) error { @@ -261,7 +261,7 @@ func (src *Int8Array) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("int8"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "int8") + return nil, errors.Errorf("unable to find oid for type name %v", "int8") } for i := range src.Elements { @@ -305,7 +305,7 @@ func (dst *Int8Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/int8range.go b/pgtype/int8range.go index 128a853f..61d860d3 100644 --- a/pgtype/int8range.go +++ b/pgtype/int8range.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Int8range struct { @@ -16,7 +16,7 @@ type Int8range struct { } func (dst *Int8range) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Int8range", src) + return errors.Errorf("cannot convert %v to Int8range", src) } func (dst *Int8range) Get() interface{} { @@ -31,7 +31,7 @@ func (dst *Int8range) Get() interface{} { } func (src *Int8range) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Int8range) DecodeText(ci *ConnInfo, src []byte) error { @@ -120,7 +120,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) + return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -130,7 +130,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -141,7 +141,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -151,7 +151,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) + return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -175,7 +175,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) + return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -185,7 +185,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) + return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -201,7 +201,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -216,7 +216,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -241,7 +241,7 @@ func (dst *Int8range) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/interval.go b/pgtype/interval.go index 85d76d99..799ce53a 100644 --- a/pgtype/interval.go +++ b/pgtype/interval.go @@ -9,6 +9,7 @@ import ( "time" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) const ( @@ -37,7 +38,7 @@ func (dst *Interval) Set(src interface{}) error { if originalSrc, ok := underlyingPtrType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Interval", value) + return errors.Errorf("cannot convert %v to Interval", value) } return nil @@ -60,7 +61,7 @@ func (src *Interval) AssignTo(dst interface{}) error { switch v := dst.(type) { case *time.Duration: if src.Days > 0 || src.Months > 0 { - return fmt.Errorf("interval with months or days cannot be decoded into %T", dst) + return errors.Errorf("interval with months or days cannot be decoded into %T", dst) } *v = time.Duration(src.Microseconds) * time.Microsecond return nil @@ -73,7 +74,7 @@ func (src *Interval) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Interval) DecodeText(ci *ConnInfo, src []byte) error { @@ -91,7 +92,7 @@ func (dst *Interval) DecodeText(ci *ConnInfo, src []byte) error { for i := 0; i < len(parts)-1; i += 2 { scalar, err := strconv.ParseInt(parts[i], 10, 64) if err != nil { - return fmt.Errorf("bad interval format") + return errors.Errorf("bad interval format") } switch parts[i+1] { @@ -107,7 +108,7 @@ func (dst *Interval) DecodeText(ci *ConnInfo, src []byte) error { if len(parts)%2 == 1 { timeParts := strings.SplitN(parts[len(parts)-1], ":", 3) if len(timeParts) != 3 { - return fmt.Errorf("bad interval format") + return errors.Errorf("bad interval format") } var negative bool @@ -118,26 +119,26 @@ func (dst *Interval) DecodeText(ci *ConnInfo, src []byte) error { hours, err := strconv.ParseInt(timeParts[0], 10, 64) if err != nil { - return fmt.Errorf("bad interval hour format: %s", timeParts[0]) + return errors.Errorf("bad interval hour format: %s", timeParts[0]) } minutes, err := strconv.ParseInt(timeParts[1], 10, 64) if err != nil { - return fmt.Errorf("bad interval minute format: %s", timeParts[1]) + return errors.Errorf("bad interval minute format: %s", timeParts[1]) } secondParts := strings.SplitN(timeParts[2], ".", 2) seconds, err := strconv.ParseInt(secondParts[0], 10, 64) if err != nil { - return fmt.Errorf("bad interval second format: %s", secondParts[0]) + return errors.Errorf("bad interval second format: %s", secondParts[0]) } var uSeconds int64 if len(secondParts) == 2 { uSeconds, err = strconv.ParseInt(secondParts[1], 10, 64) if err != nil { - return fmt.Errorf("bad interval decimal format: %s", secondParts[1]) + return errors.Errorf("bad interval decimal format: %s", secondParts[1]) } for i := 0; i < 6-len(secondParts[1]); i++ { @@ -166,7 +167,7 @@ func (dst *Interval) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 16 { - return fmt.Errorf("Received an invalid size for a interval: %d", len(src)) + return errors.Errorf("Received an invalid size for a interval: %d", len(src)) } microseconds := int64(binary.BigEndian.Uint64(src)) @@ -240,7 +241,7 @@ func (dst *Interval) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/json.go b/pgtype/json.go index ee00e9a4..562722aa 100644 --- a/pgtype/json.go +++ b/pgtype/json.go @@ -3,7 +3,8 @@ package pgtype import ( "database/sql/driver" "encoding/json" - "fmt" + + "github.com/pkg/errors" ) type JSON struct { @@ -135,7 +136,7 @@ func (dst *JSON) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/jsonb.go b/pgtype/jsonb.go index 9a06c1b4..c315c588 100644 --- a/pgtype/jsonb.go +++ b/pgtype/jsonb.go @@ -2,7 +2,8 @@ package pgtype import ( "database/sql/driver" - "fmt" + + "github.com/pkg/errors" ) type JSONB JSON @@ -30,11 +31,11 @@ func (dst *JSONB) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) == 0 { - return fmt.Errorf("jsonb too short") + return errors.Errorf("jsonb too short") } if src[0] != 1 { - return fmt.Errorf("unknown jsonb version number %d", src[0]) + return errors.Errorf("unknown jsonb version number %d", src[0]) } *dst = JSONB{Bytes: src[1:], Status: Present} diff --git a/pgtype/line.go b/pgtype/line.go index 47f636a5..f6eadf0e 100644 --- a/pgtype/line.go +++ b/pgtype/line.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Line struct { @@ -17,7 +18,7 @@ type Line struct { } func (dst *Line) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Line", src) + return errors.Errorf("cannot convert %v to Line", src) } func (dst *Line) Get() interface{} { @@ -32,7 +33,7 @@ func (dst *Line) Get() interface{} { } func (src *Line) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Line) DecodeText(ci *ConnInfo, src []byte) error { @@ -42,12 +43,12 @@ func (dst *Line) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 7 { - return fmt.Errorf("invalid length for Line: %v", len(src)) + return errors.Errorf("invalid length for Line: %v", len(src)) } parts := strings.SplitN(string(src[1:len(src)-1]), ",", 3) if len(parts) < 3 { - return fmt.Errorf("invalid format for line") + return errors.Errorf("invalid format for line") } a, err := strconv.ParseFloat(parts[0], 64) @@ -76,7 +77,7 @@ func (dst *Line) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 24 { - return fmt.Errorf("invalid length for Line: %v", len(src)) + return errors.Errorf("invalid length for Line: %v", len(src)) } a := binary.BigEndian.Uint64(src) @@ -133,7 +134,7 @@ func (dst *Line) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/lseg.go b/pgtype/lseg.go index 44c2b63c..a9d740cf 100644 --- a/pgtype/lseg.go +++ b/pgtype/lseg.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Lseg struct { @@ -17,7 +18,7 @@ type Lseg struct { } func (dst *Lseg) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Lseg", src) + return errors.Errorf("cannot convert %v to Lseg", src) } func (dst *Lseg) Get() interface{} { @@ -32,7 +33,7 @@ func (dst *Lseg) Get() interface{} { } func (src *Lseg) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Lseg) DecodeText(ci *ConnInfo, src []byte) error { @@ -42,7 +43,7 @@ func (dst *Lseg) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 11 { - return fmt.Errorf("invalid length for Lseg: %v", len(src)) + return errors.Errorf("invalid length for Lseg: %v", len(src)) } str := string(src[2:]) @@ -89,7 +90,7 @@ func (dst *Lseg) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 32 { - return fmt.Errorf("invalid length for Lseg: %v", len(src)) + return errors.Errorf("invalid length for Lseg: %v", len(src)) } x1 := binary.BigEndian.Uint64(src) @@ -151,7 +152,7 @@ func (dst *Lseg) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/macaddr.go b/pgtype/macaddr.go index e38701eb..4c6e2212 100644 --- a/pgtype/macaddr.go +++ b/pgtype/macaddr.go @@ -2,8 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "net" + + "github.com/pkg/errors" ) type Macaddr struct { @@ -32,7 +33,7 @@ func (dst *Macaddr) Set(src interface{}) error { if originalSrc, ok := underlyingPtrType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Macaddr", value) + return errors.Errorf("cannot convert %v to Macaddr", value) } return nil @@ -69,7 +70,7 @@ func (src *Macaddr) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Macaddr) DecodeText(ci *ConnInfo, src []byte) error { @@ -94,7 +95,7 @@ func (dst *Macaddr) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 6 { - return fmt.Errorf("Received an invalid size for a macaddr: %d", len(src)) + return errors.Errorf("Received an invalid size for a macaddr: %d", len(src)) } addr := make(net.HardwareAddr, 6) @@ -144,7 +145,7 @@ func (dst *Macaddr) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/numeric.go b/pgtype/numeric.go index dffb9963..fded6359 100644 --- a/pgtype/numeric.go +++ b/pgtype/numeric.go @@ -3,13 +3,13 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "math" "math/big" "strconv" "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) // PostgreSQL internal numeric storage uses 16-bit "digits" with base of 10,000 @@ -97,7 +97,7 @@ func (dst *Numeric) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Numeric", value) + return errors.Errorf("cannot convert %v to Numeric", value) } return nil @@ -136,10 +136,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt) > 0 { - return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt) < 0 { - return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int(normalizedInt.Int64()) case *int8: @@ -148,10 +148,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt8) > 0 { - return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt8) < 0 { - return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int8(normalizedInt.Int64()) case *int16: @@ -160,10 +160,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt16) > 0 { - return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt16) < 0 { - return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int16(normalizedInt.Int64()) case *int32: @@ -172,10 +172,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt32) > 0 { - return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt32) < 0 { - return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int32(normalizedInt.Int64()) case *int64: @@ -184,10 +184,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt64) > 0 { - return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt64) < 0 { - return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = normalizedInt.Int64() case *uint: @@ -196,9 +196,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) + return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint) > 0 { - return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint(normalizedInt.Uint64()) case *uint8: @@ -207,9 +207,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) + return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint8) > 0 { - return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint8(normalizedInt.Uint64()) case *uint16: @@ -218,9 +218,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) + return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint16) > 0 { - return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint16(normalizedInt.Uint64()) case *uint32: @@ -229,9 +229,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) + return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint32) > 0 { - return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint32(normalizedInt.Uint64()) case *uint64: @@ -240,9 +240,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) + return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint64) > 0 { - return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = normalizedInt.Uint64() default: @@ -276,7 +276,7 @@ func (dst *Numeric) toBigInt() (*big.Int, error) { remainder := &big.Int{} num.DivMod(num, div, remainder) if remainder.Cmp(big0) != 0 { - return nil, fmt.Errorf("cannot convert %v to integer", dst) + return nil, errors.Errorf("cannot convert %v to integer", dst) } return num, nil } @@ -328,7 +328,7 @@ func parseNumericString(str string) (n *big.Int, exp int32, err error) { accum := &big.Int{} if _, ok := accum.SetString(digits, 10); !ok { - return nil, 0, fmt.Errorf("%s is not a number", str) + return nil, 0, errors.Errorf("%s is not a number", str) } return accum, exp, nil @@ -341,7 +341,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) < 8 { - return fmt.Errorf("numeric incomplete %v", src) + return errors.Errorf("numeric incomplete %v", src) } rp := 0 @@ -361,7 +361,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error { rp += 2 if len(src[rp:]) < int(ndigits)*2 { - return fmt.Errorf("numeric incomplete %v", src) + return errors.Errorf("numeric incomplete %v", src) } accum := &big.Int{} @@ -382,7 +382,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error { case 4: mul = bigNBaseX4 default: - return fmt.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead) + return errors.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead) } accum.Mul(accum, mul) } @@ -575,7 +575,7 @@ func (dst *Numeric) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/numeric_array.go b/pgtype/numeric_array.go index f193a2a5..6dfbe5e3 100644 --- a/pgtype/numeric_array.go +++ b/pgtype/numeric_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type NumericArray struct { @@ -59,7 +59,7 @@ func (dst *NumericArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Numeric", value) + return errors.Errorf("cannot convert %v to Numeric", value) } return nil @@ -108,7 +108,7 @@ func (src *NumericArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *NumericArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -261,7 +261,7 @@ func (src *NumericArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) if dt, ok := ci.DataTypeForName("numeric"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "numeric") + return nil, errors.Errorf("unable to find oid for type name %v", "numeric") } for i := range src.Elements { @@ -305,7 +305,7 @@ func (dst *NumericArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/numrange.go b/pgtype/numrange.go index 00133296..aaed62ce 100644 --- a/pgtype/numrange.go +++ b/pgtype/numrange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Numrange struct { @@ -16,7 +16,7 @@ type Numrange struct { } func (dst *Numrange) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Numrange", src) + return errors.Errorf("cannot convert %v to Numrange", src) } func (dst *Numrange) Get() interface{} { @@ -31,7 +31,7 @@ func (dst *Numrange) Get() interface{} { } func (src *Numrange) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Numrange) DecodeText(ci *ConnInfo, src []byte) error { @@ -120,7 +120,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) + return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -130,7 +130,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -141,7 +141,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -151,7 +151,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) + return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -175,7 +175,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) + return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -185,7 +185,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) + return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -201,7 +201,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -216,7 +216,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -241,7 +241,7 @@ func (dst *Numrange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/oid.go b/pgtype/oid.go index d37f4e57..59370d66 100644 --- a/pgtype/oid.go +++ b/pgtype/oid.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "strconv" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) // OID (Object Identifier Type) is, according to @@ -20,7 +20,7 @@ type OID uint32 func (dst *OID) DecodeText(ci *ConnInfo, src []byte) error { if src == nil { - return fmt.Errorf("cannot decode nil into OID") + return errors.Errorf("cannot decode nil into OID") } n, err := strconv.ParseUint(string(src), 10, 32) @@ -34,11 +34,11 @@ func (dst *OID) DecodeText(ci *ConnInfo, src []byte) error { func (dst *OID) DecodeBinary(ci *ConnInfo, src []byte) error { if src == nil { - return fmt.Errorf("cannot decode nil into OID") + return errors.Errorf("cannot decode nil into OID") } if len(src) != 4 { - return fmt.Errorf("invalid length: %v", len(src)) + return errors.Errorf("invalid length: %v", len(src)) } n := binary.BigEndian.Uint32(src) @@ -57,7 +57,7 @@ func (src OID) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { // Scan implements the database/sql Scanner interface. func (dst *OID) Scan(src interface{}) error { if src == nil { - return fmt.Errorf("cannot scan NULL into %T", src) + return errors.Errorf("cannot scan NULL into %T", src) } switch src := src.(type) { @@ -72,7 +72,7 @@ func (dst *OID) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/path.go b/pgtype/path.go index 3575342d..aa0cee8e 100644 --- a/pgtype/path.go +++ b/pgtype/path.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Path struct { @@ -18,7 +19,7 @@ type Path struct { } func (dst *Path) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Path", src) + return errors.Errorf("cannot convert %v to Path", src) } func (dst *Path) Get() interface{} { @@ -33,7 +34,7 @@ func (dst *Path) Get() interface{} { } func (src *Path) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Path) DecodeText(ci *ConnInfo, src []byte) error { @@ -43,7 +44,7 @@ func (dst *Path) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 7 { - return fmt.Errorf("invalid length for Path: %v", len(src)) + return errors.Errorf("invalid length for Path: %v", len(src)) } closed := src[0] == '(' @@ -86,7 +87,7 @@ func (dst *Path) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return fmt.Errorf("invalid length for Path: %v", len(src)) + return errors.Errorf("invalid length for Path: %v", len(src)) } closed := src[0] == 1 @@ -95,7 +96,7 @@ func (dst *Path) DecodeBinary(ci *ConnInfo, src []byte) error { rp := 5 if 5+pointCount*16 != len(src) { - return fmt.Errorf("invalid length for Path with %d points: %v", pointCount, len(src)) + return errors.Errorf("invalid length for Path with %d points: %v", pointCount, len(src)) } points := make([]Vec2, pointCount) @@ -183,7 +184,7 @@ func (dst *Path) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/pgtype.go b/pgtype/pgtype.go index 4302a5fe..6f8e7986 100644 --- a/pgtype/pgtype.go +++ b/pgtype/pgtype.go @@ -1,8 +1,9 @@ package pgtype import ( - "errors" "reflect" + + "github.com/pkg/errors" ) // PostgreSQL oids for common types diff --git a/pgtype/pguint32.go b/pgtype/pguint32.go index 15b0f38d..e441a690 100644 --- a/pgtype/pguint32.go +++ b/pgtype/pguint32.go @@ -3,11 +3,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "math" "strconv" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) // pguint32 is the core type that is used to implement PostgreSQL types such as @@ -24,16 +24,16 @@ func (dst *pguint32) Set(src interface{}) error { switch value := src.(type) { case int64: if value < 0 { - return fmt.Errorf("%d is less than minimum value for pguint32", value) + return errors.Errorf("%d is less than minimum value for pguint32", value) } if value > math.MaxUint32 { - return fmt.Errorf("%d is greater than maximum value for pguint32", value) + return errors.Errorf("%d is greater than maximum value for pguint32", value) } *dst = pguint32{Uint: uint32(value), Status: Present} case uint32: *dst = pguint32{Uint: value, Status: Present} default: - return fmt.Errorf("cannot convert %v to pguint32", value) + return errors.Errorf("cannot convert %v to pguint32", value) } return nil @@ -58,7 +58,7 @@ func (src *pguint32) AssignTo(dst interface{}) error { if src.Status == Present { *v = src.Uint } else { - return fmt.Errorf("cannot assign %v into %T", src, dst) + return errors.Errorf("cannot assign %v into %T", src, dst) } case **uint32: if src.Status == Present { @@ -94,7 +94,7 @@ func (dst *pguint32) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 4 { - return fmt.Errorf("invalid length: %v", len(src)) + return errors.Errorf("invalid length: %v", len(src)) } n := binary.BigEndian.Uint32(src) @@ -146,7 +146,7 @@ func (dst *pguint32) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/point.go b/pgtype/point.go index 3d5d4e1a..3132a939 100644 --- a/pgtype/point.go +++ b/pgtype/point.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Vec2 struct { @@ -22,7 +23,7 @@ type Point struct { } func (dst *Point) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Point", src) + return errors.Errorf("cannot convert %v to Point", src) } func (dst *Point) Get() interface{} { @@ -37,7 +38,7 @@ func (dst *Point) Get() interface{} { } func (src *Point) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Point) DecodeText(ci *ConnInfo, src []byte) error { @@ -47,12 +48,12 @@ func (dst *Point) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return fmt.Errorf("invalid length for point: %v", len(src)) + return errors.Errorf("invalid length for point: %v", len(src)) } parts := strings.SplitN(string(src[1:len(src)-1]), ",", 2) if len(parts) < 2 { - return fmt.Errorf("invalid format for point") + return errors.Errorf("invalid format for point") } x, err := strconv.ParseFloat(parts[0], 64) @@ -76,7 +77,7 @@ func (dst *Point) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 16 { - return fmt.Errorf("invalid length for point: %v", len(src)) + return errors.Errorf("invalid length for point: %v", len(src)) } x := binary.BigEndian.Uint64(src) @@ -129,7 +130,7 @@ func (dst *Point) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/polygon.go b/pgtype/polygon.go index d0b50061..3f3d9f53 100644 --- a/pgtype/polygon.go +++ b/pgtype/polygon.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Polygon struct { @@ -17,7 +18,7 @@ type Polygon struct { } func (dst *Polygon) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Polygon", src) + return errors.Errorf("cannot convert %v to Polygon", src) } func (dst *Polygon) Get() interface{} { @@ -32,7 +33,7 @@ func (dst *Polygon) Get() interface{} { } func (src *Polygon) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Polygon) DecodeText(ci *ConnInfo, src []byte) error { @@ -42,7 +43,7 @@ func (dst *Polygon) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 7 { - return fmt.Errorf("invalid length for Polygon: %v", len(src)) + return errors.Errorf("invalid length for Polygon: %v", len(src)) } points := make([]Vec2, 0) @@ -84,14 +85,14 @@ func (dst *Polygon) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return fmt.Errorf("invalid length for Polygon: %v", len(src)) + return errors.Errorf("invalid length for Polygon: %v", len(src)) } pointCount := int(binary.BigEndian.Uint32(src)) rp := 4 if 4+pointCount*16 != len(src) { - return fmt.Errorf("invalid length for Polygon with %d points: %v", pointCount, len(src)) + return errors.Errorf("invalid length for Polygon with %d points: %v", pointCount, len(src)) } points := make([]Vec2, pointCount) @@ -164,7 +165,7 @@ func (dst *Polygon) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/qchar.go b/pgtype/qchar.go index 9c40ce18..064dab1e 100644 --- a/pgtype/qchar.go +++ b/pgtype/qchar.go @@ -1,9 +1,10 @@ package pgtype import ( - "fmt" "math" "strconv" + + "github.com/pkg/errors" ) // QChar is for PostgreSQL's special 8-bit-only "char" type more akin to the C @@ -33,59 +34,59 @@ func (dst *QChar) Set(src interface{}) error { *dst = QChar{Int: value, Status: Present} case uint8: if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int16: if value < math.MinInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint16: if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int32: if value < math.MinInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint32: if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int64: if value < math.MinInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint64: if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int: if value < math.MinInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint: if value > math.MaxInt8 { - return fmt.Errorf("%d is greater than maximum value for QChar", value) + return errors.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case string: @@ -98,7 +99,7 @@ func (dst *QChar) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to QChar", value) + return errors.Errorf("cannot convert %v to QChar", value) } return nil @@ -126,7 +127,7 @@ func (dst *QChar) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 1 { - return fmt.Errorf(`invalid length for "char": %v`, len(src)) + return errors.Errorf(`invalid length for "char": %v`, len(src)) } *dst = QChar{Int: int8(src[0]), Status: Present} diff --git a/pgtype/range.go b/pgtype/range.go index 76daf8cc..d870834f 100644 --- a/pgtype/range.go +++ b/pgtype/range.go @@ -3,7 +3,8 @@ package pgtype import ( "bytes" "encoding/binary" - "fmt" + + "github.com/pkg/errors" ) type BoundType byte @@ -36,7 +37,7 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { r, _, err := buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid lower bound: %v", err) + return nil, errors.Errorf("invalid lower bound: %v", err) } switch r { case '(': @@ -44,12 +45,12 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { case '[': utr.LowerType = Inclusive default: - return nil, fmt.Errorf("missing lower bound, instead got: %v", string(r)) + return nil, errors.Errorf("missing lower bound, instead got: %v", string(r)) } r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid lower value: %v", err) + return nil, errors.Errorf("invalid lower value: %v", err) } buf.UnreadRune() @@ -58,21 +59,21 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { } else { utr.Lower, err = rangeParseValue(buf) if err != nil { - return nil, fmt.Errorf("invalid lower value: %v", err) + return nil, errors.Errorf("invalid lower value: %v", err) } } r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("missing range separator: %v", err) + return nil, errors.Errorf("missing range separator: %v", err) } if r != ',' { - return nil, fmt.Errorf("missing range separator: %v", r) + return nil, errors.Errorf("missing range separator: %v", r) } r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("invalid upper value: %v", err) + return nil, errors.Errorf("invalid upper value: %v", err) } buf.UnreadRune() @@ -81,13 +82,13 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { } else { utr.Upper, err = rangeParseValue(buf) if err != nil { - return nil, fmt.Errorf("invalid upper value: %v", err) + return nil, errors.Errorf("invalid upper value: %v", err) } } r, _, err = buf.ReadRune() if err != nil { - return nil, fmt.Errorf("missing upper bound: %v", err) + return nil, errors.Errorf("missing upper bound: %v", err) } switch r { case ')': @@ -95,13 +96,13 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { case ']': utr.UpperType = Inclusive default: - return nil, fmt.Errorf("missing upper bound, instead got: %v", string(r)) + return nil, errors.Errorf("missing upper bound, instead got: %v", string(r)) } skipWhitespace(buf) if buf.Len() > 0 { - return nil, fmt.Errorf("unexpected trailing data: %v", buf.String()) + return nil, errors.Errorf("unexpected trailing data: %v", buf.String()) } return utr, nil @@ -197,7 +198,7 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { ubr := &UntypedBinaryRange{} if len(src) == 0 { - return nil, fmt.Errorf("range too short: %v", len(src)) + return nil, errors.Errorf("range too short: %v", len(src)) } rangeType := src[0] @@ -205,7 +206,7 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { if rangeType&emptyMask > 0 { if len(src[rp:]) > 0 { - return nil, fmt.Errorf("unexpected trailing bytes parsing empty range: %v", len(src[rp:])) + return nil, errors.Errorf("unexpected trailing bytes parsing empty range: %v", len(src[rp:])) } ubr.LowerType = Empty ubr.UpperType = Empty @@ -230,13 +231,13 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { if ubr.LowerType == Unbounded && ubr.UpperType == Unbounded { if len(src[rp:]) > 0 { - return nil, fmt.Errorf("unexpected trailing bytes parsing unbounded range: %v", len(src[rp:])) + return nil, errors.Errorf("unexpected trailing bytes parsing unbounded range: %v", len(src[rp:])) } return ubr, nil } if len(src[rp:]) < 4 { - return nil, fmt.Errorf("too few bytes for size: %v", src[rp:]) + return nil, errors.Errorf("too few bytes for size: %v", src[rp:]) } valueLen := int(binary.BigEndian.Uint32(src[rp:])) rp += 4 @@ -249,14 +250,14 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { } else { ubr.Upper = val if len(src[rp:]) > 0 { - return nil, fmt.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) + return nil, errors.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) } return ubr, nil } if ubr.UpperType != Unbounded { if len(src[rp:]) < 4 { - return nil, fmt.Errorf("too few bytes for size: %v", src[rp:]) + return nil, errors.Errorf("too few bytes for size: %v", src[rp:]) } valueLen := int(binary.BigEndian.Uint32(src[rp:])) rp += 4 @@ -265,7 +266,7 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { } if len(src[rp:]) > 0 { - return nil, fmt.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) + return nil, errors.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) } return ubr, nil diff --git a/pgtype/record.go b/pgtype/record.go index 7c8736df..14b415c3 100644 --- a/pgtype/record.go +++ b/pgtype/record.go @@ -2,7 +2,8 @@ package pgtype import ( "encoding/binary" - "fmt" + + "github.com/pkg/errors" ) // Record is the generic PostgreSQL record type such as is created with the @@ -25,7 +26,7 @@ func (dst *Record) Set(src interface{}) error { case []Value: *dst = Record{Fields: value, Status: Present} default: - return fmt.Errorf("cannot convert %v to Record", src) + return errors.Errorf("cannot convert %v to Record", src) } return nil @@ -65,7 +66,7 @@ func (src *Record) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Record) DecodeBinary(ci *ConnInfo, src []byte) error { @@ -77,7 +78,7 @@ func (dst *Record) DecodeBinary(ci *ConnInfo, src []byte) error { rp := 0 if len(src[rp:]) < 4 { - return fmt.Errorf("Record incomplete %v", src) + return errors.Errorf("Record incomplete %v", src) } fieldCount := int(int32(binary.BigEndian.Uint32(src[rp:]))) rp += 4 @@ -86,7 +87,7 @@ func (dst *Record) DecodeBinary(ci *ConnInfo, src []byte) error { for i := 0; i < fieldCount; i++ { if len(src[rp:]) < 8 { - return fmt.Errorf("Record incomplete %v", src) + return errors.Errorf("Record incomplete %v", src) } fieldOID := OID(binary.BigEndian.Uint32(src[rp:])) rp += 4 @@ -97,14 +98,14 @@ func (dst *Record) DecodeBinary(ci *ConnInfo, src []byte) error { var binaryDecoder BinaryDecoder if dt, ok := ci.DataTypeForOID(fieldOID); ok { if binaryDecoder, ok = dt.Value.(BinaryDecoder); !ok { - return fmt.Errorf("unknown oid while decoding record: %v", fieldOID) + return errors.Errorf("unknown oid while decoding record: %v", fieldOID) } } var fieldBytes []byte if fieldLen >= 0 { if len(src[rp:]) < fieldLen { - return fmt.Errorf("Record incomplete %v", src) + return errors.Errorf("Record incomplete %v", src) } fieldBytes = src[rp : rp+fieldLen] rp += fieldLen diff --git a/pgtype/text.go b/pgtype/text.go index 6638c354..f05e1e89 100644 --- a/pgtype/text.go +++ b/pgtype/text.go @@ -3,7 +3,8 @@ package pgtype import ( "database/sql/driver" "encoding/json" - "fmt" + + "github.com/pkg/errors" ) type Text struct { @@ -36,7 +37,7 @@ func (dst *Text) Set(src interface{}) error { if originalSrc, ok := underlyingStringType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Text", value) + return errors.Errorf("cannot convert %v to Text", value) } return nil @@ -73,7 +74,7 @@ func (src *Text) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Text) DecodeText(ci *ConnInfo, src []byte) error { @@ -121,7 +122,7 @@ func (dst *Text) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/text_array.go b/pgtype/text_array.go index dab7d36e..2609a2cc 100644 --- a/pgtype/text_array.go +++ b/pgtype/text_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type TextArray struct { @@ -40,7 +40,7 @@ func (dst *TextArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Text", value) + return errors.Errorf("cannot convert %v to Text", value) } return nil @@ -80,7 +80,7 @@ func (src *TextArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *TextArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -233,7 +233,7 @@ func (src *TextArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("text"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "text") + return nil, errors.Errorf("unable to find oid for type name %v", "text") } for i := range src.Elements { @@ -277,7 +277,7 @@ func (dst *TextArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/tid.go b/pgtype/tid.go index d44ea3a6..21852a14 100644 --- a/pgtype/tid.go +++ b/pgtype/tid.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) // TID is PostgreSQL's Tuple Identifier type. @@ -28,7 +29,7 @@ type TID struct { } func (dst *TID) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to TID", src) + return errors.Errorf("cannot convert %v to TID", src) } func (dst *TID) Get() interface{} { @@ -43,7 +44,7 @@ func (dst *TID) Get() interface{} { } func (src *TID) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *TID) DecodeText(ci *ConnInfo, src []byte) error { @@ -53,12 +54,12 @@ func (dst *TID) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return fmt.Errorf("invalid length for tid: %v", len(src)) + return errors.Errorf("invalid length for tid: %v", len(src)) } parts := strings.SplitN(string(src[1:len(src)-1]), ",", 2) if len(parts) < 2 { - return fmt.Errorf("invalid format for tid") + return errors.Errorf("invalid format for tid") } blockNumber, err := strconv.ParseUint(parts[0], 10, 32) @@ -82,7 +83,7 @@ func (dst *TID) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 6 { - return fmt.Errorf("invalid length for tid: %v", len(src)) + return errors.Errorf("invalid length for tid: %v", len(src)) } *dst = TID{ @@ -134,7 +135,7 @@ func (dst *TID) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/timestamp.go b/pgtype/timestamp.go index 75c6cffa..d906f467 100644 --- a/pgtype/timestamp.go +++ b/pgtype/timestamp.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "time" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) const pgTimestampFormat = "2006-01-02 15:04:05.999999999" @@ -37,7 +37,7 @@ func (dst *Timestamp) Set(src interface{}) error { if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Timestamp", value) + return errors.Errorf("cannot convert %v to Timestamp", value) } return nil @@ -63,7 +63,7 @@ func (src *Timestamp) AssignTo(dst interface{}) error { switch v := dst.(type) { case *time.Time: if src.InfinityModifier != None { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } *v = src.Time return nil @@ -76,7 +76,7 @@ func (src *Timestamp) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } // DecodeText decodes from src into dst. The decoded time is considered to @@ -114,7 +114,7 @@ func (dst *Timestamp) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return fmt.Errorf("invalid length for timestamp: %v", len(src)) + return errors.Errorf("invalid length for timestamp: %v", len(src)) } microsecSinceY2K := int64(binary.BigEndian.Uint64(src)) @@ -143,7 +143,7 @@ func (src *Timestamp) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } if src.Time.Location() != time.UTC { - return nil, fmt.Errorf("cannot encode non-UTC time into timestamp") + return nil, errors.Errorf("cannot encode non-UTC time into timestamp") } var s string @@ -170,7 +170,7 @@ func (src *Timestamp) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } if src.Time.Location() != time.UTC { - return nil, fmt.Errorf("cannot encode non-UTC time into timestamp") + return nil, errors.Errorf("cannot encode non-UTC time into timestamp") } var microsecSinceY2K int64 @@ -206,7 +206,7 @@ func (dst *Timestamp) Scan(src interface{}) error { return nil } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/timestamp_array.go b/pgtype/timestamp_array.go index fca9ad93..be281f2e 100644 --- a/pgtype/timestamp_array.go +++ b/pgtype/timestamp_array.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "time" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type TimestampArray struct { @@ -41,7 +41,7 @@ func (dst *TimestampArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Timestamp", value) + return errors.Errorf("cannot convert %v to Timestamp", value) } return nil @@ -81,7 +81,7 @@ func (src *TimestampArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *TimestampArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -234,7 +234,7 @@ func (src *TimestampArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error if dt, ok := ci.DataTypeForName("timestamp"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "timestamp") + return nil, errors.Errorf("unable to find oid for type name %v", "timestamp") } for i := range src.Elements { @@ -278,7 +278,7 @@ func (dst *TimestampArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/timestamptz.go b/pgtype/timestamptz.go index 97b0de2a..74fe4954 100644 --- a/pgtype/timestamptz.go +++ b/pgtype/timestamptz.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "time" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) const pgTimestamptzHourFormat = "2006-01-02 15:04:05.999999999Z07" @@ -38,7 +38,7 @@ func (dst *Timestamptz) Set(src interface{}) error { if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Timestamptz", value) + return errors.Errorf("cannot convert %v to Timestamptz", value) } return nil @@ -64,7 +64,7 @@ func (src *Timestamptz) AssignTo(dst interface{}) error { switch v := dst.(type) { case *time.Time: if src.InfinityModifier != None { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } *v = src.Time return nil @@ -77,7 +77,7 @@ func (src *Timestamptz) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *Timestamptz) DecodeText(ci *ConnInfo, src []byte) error { @@ -120,7 +120,7 @@ func (dst *Timestamptz) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return fmt.Errorf("invalid length for timestamptz: %v", len(src)) + return errors.Errorf("invalid length for timestamptz: %v", len(src)) } microsecSinceY2K := int64(binary.BigEndian.Uint64(src)) @@ -202,7 +202,7 @@ func (dst *Timestamptz) Scan(src interface{}) error { return nil } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/timestamptz_array.go b/pgtype/timestamptz_array.go index e0866d69..086a4ef0 100644 --- a/pgtype/timestamptz_array.go +++ b/pgtype/timestamptz_array.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "time" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type TimestamptzArray struct { @@ -41,7 +41,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Timestamptz", value) + return errors.Errorf("cannot convert %v to Timestamptz", value) } return nil @@ -81,7 +81,7 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *TimestamptzArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -234,7 +234,7 @@ func (src *TimestamptzArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err if dt, ok := ci.DataTypeForName("timestamptz"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "timestamptz") + return nil, errors.Errorf("unable to find oid for type name %v", "timestamptz") } for i := range src.Elements { @@ -278,7 +278,7 @@ func (dst *TimestamptzArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/tsrange.go b/pgtype/tsrange.go index 783fb086..8a67d65e 100644 --- a/pgtype/tsrange.go +++ b/pgtype/tsrange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Tsrange struct { @@ -16,7 +16,7 @@ type Tsrange struct { } func (dst *Tsrange) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Tsrange", src) + return errors.Errorf("cannot convert %v to Tsrange", src) } func (dst *Tsrange) Get() interface{} { @@ -31,7 +31,7 @@ func (dst *Tsrange) Get() interface{} { } func (src *Tsrange) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Tsrange) DecodeText(ci *ConnInfo, src []byte) error { @@ -120,7 +120,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) + return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -130,7 +130,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -141,7 +141,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -151,7 +151,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) + return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -175,7 +175,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) + return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -185,7 +185,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) + return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -201,7 +201,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -216,7 +216,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -241,7 +241,7 @@ func (dst *Tsrange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/tstzrange.go b/pgtype/tstzrange.go index 8fd3fd68..b5129093 100644 --- a/pgtype/tstzrange.go +++ b/pgtype/tstzrange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Tstzrange struct { @@ -16,7 +16,7 @@ type Tstzrange struct { } func (dst *Tstzrange) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Tstzrange", src) + return errors.Errorf("cannot convert %v to Tstzrange", src) } func (dst *Tstzrange) Get() interface{} { @@ -31,7 +31,7 @@ func (dst *Tstzrange) Get() interface{} { } func (src *Tstzrange) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Tstzrange) DecodeText(ci *ConnInfo, src []byte) error { @@ -120,7 +120,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) + return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -130,7 +130,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -141,7 +141,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -151,7 +151,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) + return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -175,7 +175,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) + return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -185,7 +185,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) + return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -201,7 +201,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -216,7 +216,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -241,7 +241,7 @@ func (dst *Tstzrange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/typed_array.go.erb b/pgtype/typed_array.go.erb index 01072549..7a69d0ab 100644 --- a/pgtype/typed_array.go.erb +++ b/pgtype/typed_array.go.erb @@ -40,7 +40,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to <%= pgtype_element_type %>", value) + return errors.Errorf("cannot convert %v to <%= pgtype_element_type %>", value) } return nil @@ -80,7 +80,7 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *<%= pgtype_array_type %>) DecodeText(ci *ConnInfo, src []byte) error { @@ -236,7 +236,7 @@ func (src *<%= pgtype_array_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byt if dt, ok := ci.DataTypeForName("<%= element_type_name %>"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "<%= element_type_name %>") + return nil, errors.Errorf("unable to find oid for type name %v", "<%= element_type_name %>") } for i := range src.Elements { @@ -281,7 +281,7 @@ func (dst *<%= pgtype_array_type %>) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/typed_range.go.erb b/pgtype/typed_range.go.erb index 90c23991..91a5cb97 100644 --- a/pgtype/typed_range.go.erb +++ b/pgtype/typed_range.go.erb @@ -18,7 +18,7 @@ type <%= range_type %> struct { } func (dst *<%= range_type %>) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to <%= range_type %>", src) + return errors.Errorf("cannot convert %v to <%= range_type %>", src) } func (dst *<%= range_type %>) Get() interface{} { @@ -33,7 +33,7 @@ func (dst *<%= range_type %>) Get() interface{} { } func (src *<%= range_type %>) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *<%= range_type %>) DecodeText(ci *ConnInfo, src []byte) error { @@ -122,7 +122,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error case Empty: return append(buf, "empty"...), nil default: - return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) + return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -132,7 +132,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -143,7 +143,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error if err != nil { return nil, err } else if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -153,7 +153,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error case Inclusive: buf = append(buf, ']') default: - return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) + return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -177,7 +177,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err case Empty: return append(buf, emptyMask), nil default: - return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) + return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -187,7 +187,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err rangeType |= upperUnboundedMask case Exclusive: default: - return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) + return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -203,7 +203,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err return nil, err } if buf == nil { - return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -218,7 +218,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err return nil, err } if buf == nil { - return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -243,7 +243,7 @@ func (dst *<%= range_type %>) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/uuid.go b/pgtype/uuid.go index d1ab1a38..33e79536 100644 --- a/pgtype/uuid.go +++ b/pgtype/uuid.go @@ -4,6 +4,8 @@ import ( "database/sql/driver" "encoding/hex" "fmt" + + "github.com/pkg/errors" ) type UUID struct { @@ -17,7 +19,7 @@ func (dst *UUID) Set(src interface{}) error { *dst = UUID{Bytes: value, Status: Present} case []byte: if len(value) != 16 { - return fmt.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) + return errors.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) } *dst = UUID{Status: Present} copy(dst.Bytes[:], value) @@ -31,7 +33,7 @@ func (dst *UUID) Set(src interface{}) error { if originalSrc, ok := underlyingPtrType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to UUID", value) + return errors.Errorf("cannot convert %v to UUID", value) } return nil @@ -71,7 +73,7 @@ func (src *UUID) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot assign %v into %T", src, dst) + return errors.Errorf("cannot assign %v into %T", src, dst) } // parseUUID converts a string UUID in standard form to a byte array. @@ -98,7 +100,7 @@ func (dst *UUID) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) != 36 { - return fmt.Errorf("invalid length for UUID: %v", len(src)) + return errors.Errorf("invalid length for UUID: %v", len(src)) } buf, err := parseUUID(string(src)) @@ -117,7 +119,7 @@ func (dst *UUID) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 16 { - return fmt.Errorf("invalid length for UUID: %v", len(src)) + return errors.Errorf("invalid length for UUID: %v", len(src)) } *dst = UUID{Status: Present} @@ -163,7 +165,7 @@ func (dst *UUID) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/varbit.go b/pgtype/varbit.go index 9a9fe1e1..dfa194d2 100644 --- a/pgtype/varbit.go +++ b/pgtype/varbit.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type Varbit struct { @@ -15,7 +15,7 @@ type Varbit struct { } func (dst *Varbit) Set(src interface{}) error { - return fmt.Errorf("cannot convert %v to Varbit", src) + return errors.Errorf("cannot convert %v to Varbit", src) } func (dst *Varbit) Get() interface{} { @@ -30,7 +30,7 @@ func (dst *Varbit) Get() interface{} { } func (src *Varbit) AssignTo(dst interface{}) error { - return fmt.Errorf("cannot assign %v to %T", src, dst) + return errors.Errorf("cannot assign %v to %T", src, dst) } func (dst *Varbit) DecodeText(ci *ConnInfo, src []byte) error { @@ -65,7 +65,7 @@ func (dst *Varbit) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) < 4 { - return fmt.Errorf("invalid length for varbit: %v", len(src)) + return errors.Errorf("invalid length for varbit: %v", len(src)) } bitLen := int32(binary.BigEndian.Uint32(src)) @@ -124,7 +124,7 @@ func (dst *Varbit) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype/varchar_array.go b/pgtype/varchar_array.go index 95b5cfc1..fecbb2e5 100644 --- a/pgtype/varchar_array.go +++ b/pgtype/varchar_array.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" - "fmt" "github.com/jackc/pgx/pgio" + "github.com/pkg/errors" ) type VarcharArray struct { @@ -40,7 +40,7 @@ func (dst *VarcharArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return fmt.Errorf("cannot convert %v to Varchar", value) + return errors.Errorf("cannot convert %v to Varchar", value) } return nil @@ -80,7 +80,7 @@ func (src *VarcharArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return fmt.Errorf("cannot decode %v into %T", src, dst) + return errors.Errorf("cannot decode %v into %T", src, dst) } func (dst *VarcharArray) DecodeText(ci *ConnInfo, src []byte) error { @@ -233,7 +233,7 @@ func (src *VarcharArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) if dt, ok := ci.DataTypeForName("varchar"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, fmt.Errorf("unable to find oid for type name %v", "varchar") + return nil, errors.Errorf("unable to find oid for type name %v", "varchar") } for i := range src.Elements { @@ -277,7 +277,7 @@ func (dst *VarcharArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return fmt.Errorf("cannot scan %T", src) + return errors.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/query.go b/query.go index c12d64f0..811e95b1 100644 --- a/query.go +++ b/query.go @@ -3,10 +3,11 @@ package pgx import ( "context" "database/sql" - "errors" "fmt" "time" + "github.com/pkg/errors" + "github.com/jackc/pgx/internal/sanitize" "github.com/jackc/pgx/pgproto3" "github.com/jackc/pgx/pgtype" @@ -135,7 +136,7 @@ func (rows *Rows) Next() bool { rows.fields[i].DataTypeName = dt.Name rows.fields[i].FormatCode = TextFormatCode } else { - rows.fatal(fmt.Errorf("unknown oid: %d", rows.fields[i].DataType)) + rows.fatal(errors.Errorf("unknown oid: %d", rows.fields[i].DataType)) return false } } @@ -191,7 +192,7 @@ func (e scanArgError) Error() string { // copy the raw bytes received from PostgreSQL. nil will skip the value entirely. func (rows *Rows) Scan(dest ...interface{}) (err error) { if len(rows.fields) != len(dest) { - err = fmt.Errorf("Scan received wrong number of arguments, got %d but expected %d", len(dest), len(rows.fields)) + err = errors.Errorf("Scan received wrong number of arguments, got %d but expected %d", len(dest), len(rows.fields)) rows.fatal(err) return err } @@ -224,7 +225,7 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) { rows.fatal(scanArgError{col: i, err: err}) } } else { - rows.fatal(scanArgError{col: i, err: fmt.Errorf("%T is not a pgtype.TextDecoder", value)}) + rows.fatal(scanArgError{col: i, err: errors.Errorf("%T is not a pgtype.TextDecoder", value)}) } case BinaryFormatCode: if binaryDecoder, ok := value.(pgtype.BinaryDecoder); ok { @@ -233,10 +234,10 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) { rows.fatal(scanArgError{col: i, err: err}) } } else { - rows.fatal(scanArgError{col: i, err: fmt.Errorf("%T is not a pgtype.BinaryDecoder", value)}) + rows.fatal(scanArgError{col: i, err: errors.Errorf("%T is not a pgtype.BinaryDecoder", value)}) } default: - rows.fatal(scanArgError{col: i, err: fmt.Errorf("unknown format code: %v", fd.FormatCode)}) + rows.fatal(scanArgError{col: i, err: errors.Errorf("unknown format code: %v", fd.FormatCode)}) } if rows.Err() == nil { @@ -254,7 +255,7 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) { } } } else { - rows.fatal(scanArgError{col: i, err: fmt.Errorf("unknown oid: %v", fd.DataType)}) + rows.fatal(scanArgError{col: i, err: errors.Errorf("unknown oid: %v", fd.DataType)}) } } @@ -464,11 +465,11 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions, func (c *Conn) buildOneRoundTripQueryEx(buf []byte, sql string, options *QueryExOptions, arguments []interface{}) ([]byte, error) { if len(arguments) != len(options.ParameterOIDs) { - return nil, fmt.Errorf("mismatched number of arguments (%d) and options.ParameterOIDs (%d)", len(arguments), len(options.ParameterOIDs)) + return nil, errors.Errorf("mismatched number of arguments (%d) and options.ParameterOIDs (%d)", len(arguments), len(options.ParameterOIDs)) } if len(options.ParameterOIDs) > 65535 { - return nil, fmt.Errorf("Number of QueryExOptions ParameterOIDs must be between 0 and 65535, received %d", len(options.ParameterOIDs)) + return nil, errors.Errorf("Number of QueryExOptions ParameterOIDs must be between 0 and 65535, received %d", len(options.ParameterOIDs)) } buf = appendParse(buf, "", sql, options.ParameterOIDs) @@ -497,7 +498,7 @@ func (c *Conn) readUntilRowDescription() ([]FieldDescription, error) { if dt, ok := c.ConnInfo.DataTypeForOID(fieldDescriptions[i].DataType); ok { fieldDescriptions[i].DataTypeName = dt.Name } else { - return nil, fmt.Errorf("unknown oid: %d", fieldDescriptions[i].DataType) + return nil, errors.Errorf("unknown oid: %d", fieldDescriptions[i].DataType) } } return fieldDescriptions, nil diff --git a/replication.go b/replication.go index 1bf69c4e..bfa81e54 100644 --- a/replication.go +++ b/replication.go @@ -3,10 +3,11 @@ package pgx import ( "context" "encoding/binary" - "errors" "fmt" "time" + "github.com/pkg/errors" + "github.com/jackc/pgx/pgio" "github.com/jackc/pgx/pgproto3" ) diff --git a/stdlib/sql.go b/stdlib/sql.go index b9cd3295..0c140343 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -68,12 +68,13 @@ import ( "database/sql" "database/sql/driver" "encoding/binary" - "errors" "fmt" "io" "strings" "sync" + "github.com/pkg/errors" + "github.com/jackc/pgx" "github.com/jackc/pgx/pgtype" ) @@ -260,7 +261,7 @@ func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e case sql.LevelSerializable: pgxOpts.IsoLevel = pgx.Serializable default: - return nil, fmt.Errorf("unsupported isolation: %v", opts.Isolation) + return nil, errors.Errorf("unsupported isolation: %v", opts.Isolation) } if opts.ReadOnly { @@ -546,7 +547,7 @@ func ReleaseConn(db *sql.DB, conn *pgx.Conn) error { driver.fakeTxMutex.Unlock() } else { driver.fakeTxMutex.Unlock() - return fmt.Errorf("can't release conn that is not acquired") + return errors.Errorf("can't release conn that is not acquired") } return tx.Rollback() diff --git a/stress_test.go b/stress_test.go index 93752c29..114bec81 100644 --- a/stress_test.go +++ b/stress_test.go @@ -2,7 +2,6 @@ package pgx_test import ( "context" - "errors" "fmt" "math/rand" "os" @@ -10,6 +9,8 @@ import ( "testing" "time" + "github.com/pkg/errors" + "github.com/jackc/fake" "github.com/jackc/pgx" ) @@ -73,7 +74,7 @@ func TestStressConnPool(t *testing.T) { action := actions[rand.Intn(len(actions))] err := action.fn(pool, n) if err != nil { - errChan <- fmt.Errorf("%s: %v", action.name, err) + errChan <- errors.Errorf("%s: %v", action.name, err) break } } @@ -235,7 +236,7 @@ func poolPrepareUseAndDeallocate(pool *pgx.ConnPool, actionNum int) error { } if s != "hello" { - return fmt.Errorf("Prepared statement did not return expected value: %v", s) + return errors.Errorf("Prepared statement did not return expected value: %v", s) } return pool.Deallocate(psName) @@ -328,7 +329,7 @@ func canceledQueryExContext(pool *pgx.ConnPool, actionNum int) error { if err == context.Canceled { return nil } else if err != nil { - return fmt.Errorf("Only allowed error is context.Canceled, got %v", err) + return errors.Errorf("Only allowed error is context.Canceled, got %v", err) } for rows.Next() { @@ -336,7 +337,7 @@ func canceledQueryExContext(pool *pgx.ConnPool, actionNum int) error { } if rows.Err() != context.Canceled { - return fmt.Errorf("Expected context.Canceled error, got %v", rows.Err()) + return errors.Errorf("Expected context.Canceled error, got %v", rows.Err()) } return nil @@ -351,7 +352,7 @@ func canceledExecExContext(pool *pgx.ConnPool, actionNum int) error { _, err := pool.ExecEx(ctx, "select pg_sleep(2)", nil) if err != context.Canceled { - return fmt.Errorf("Expected context.Canceled error, got %v", err) + return errors.Errorf("Expected context.Canceled error, got %v", err) } return nil diff --git a/tx.go b/tx.go index e144337d..f9607f70 100644 --- a/tx.go +++ b/tx.go @@ -3,9 +3,10 @@ package pgx import ( "bytes" "context" - "errors" "fmt" "time" + + "github.com/pkg/errors" ) type TxIsoLevel string diff --git a/v3.md b/v3.md index 993f9e24..d2afbf39 100644 --- a/v3.md +++ b/v3.md @@ -56,6 +56,8 @@ Use Go casing convention for OID, UUID, JSON(B), ACLItem, CID, TID, XID, and CID Add OnNotice +Use github.com/pkg/errors + ## TODO / Possible / Investigate Organize errors better diff --git a/values.go b/values.go index a6c350f6..86ae3afe 100644 --- a/values.go +++ b/values.go @@ -9,6 +9,7 @@ import ( "github.com/jackc/pgx/pgio" "github.com/jackc/pgx/pgtype" + "github.com/pkg/errors" ) // PostgreSQL format codes @@ -69,12 +70,12 @@ func convertSimpleArgument(ci *pgtype.ConnInfo, arg interface{}) (interface{}, e return int64(arg), nil case uint64: if arg > math.MaxInt64 { - return nil, fmt.Errorf("arg too big for int64: %v", arg) + return nil, errors.Errorf("arg too big for int64: %v", arg) } return int64(arg), nil case uint: if arg > math.MaxInt64 { - return nil, fmt.Errorf("arg too big for int64: %v", arg) + return nil, errors.Errorf("arg too big for int64: %v", arg) } return int64(arg), nil case float32: