From a5f166bd217dcdd8691694185207116d89ccb289 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sun, 4 Jun 2017 21:30:03 -0500 Subject: [PATCH] Use github.com/pkg/errors --- aclitem.go | 9 ++--- aclitem_array.go | 9 ++--- array.go | 36 +++++++++---------- bool.go | 13 +++---- bool_array.go | 10 +++--- box.go | 11 +++--- bytea.go | 11 +++--- bytea_array.go | 10 +++--- cidr_array.go | 10 +++--- circle.go | 11 +++--- convert.go | 59 ++++++++++++++++--------------- database_sql.go | 3 +- date.go | 12 +++---- date_array.go | 10 +++--- daterange.go | 24 ++++++------- ext/satori-uuid/uuid.go | 14 ++++---- ext/shopspring-numeric/decimal.go | 52 +++++++++++++-------------- float4.go | 20 +++++------ float4_array.go | 10 +++--- float8.go | 16 ++++----- float8_array.go | 10 +++--- hstore.go | 32 ++++++++--------- hstore_array.go | 10 +++--- inet.go | 15 ++++---- inet_array.go | 10 +++--- int2.go | 32 ++++++++--------- int2_array.go | 10 +++--- int4.go | 26 +++++++------- int4_array.go | 10 +++--- int4range.go | 24 ++++++------- int8.go | 16 ++++----- int8_array.go | 10 +++--- int8range.go | 24 ++++++------- interval.go | 23 ++++++------ json.go | 5 +-- jsonb.go | 7 ++-- line.go | 13 +++---- lseg.go | 11 +++--- macaddr.go | 11 +++--- numeric.go | 56 ++++++++++++++--------------- numeric_array.go | 10 +++--- numrange.go | 24 ++++++------- oid.go | 12 +++---- path.go | 13 +++---- pgtype.go | 3 +- pguint32.go | 14 ++++---- point.go | 13 +++---- polygon.go | 13 +++---- qchar.go | 33 ++++++++--------- range.go | 39 ++++++++++---------- record.go | 15 ++++---- text.go | 9 ++--- text_array.go | 10 +++--- tid.go | 13 +++---- timestamp.go | 16 ++++----- timestamp_array.go | 10 +++--- timestamptz.go | 12 +++---- timestamptz_array.go | 10 +++--- tsrange.go | 24 ++++++------- tstzrange.go | 24 ++++++------- typed_array.go.erb | 8 ++--- typed_range.go.erb | 22 ++++++------ uuid.go | 14 ++++---- varbit.go | 10 +++--- varchar_array.go | 10 +++--- 65 files changed, 556 insertions(+), 530 deletions(-) diff --git a/aclitem.go b/aclitem.go index 829eb908..35269e91 100644 --- a/aclitem.go +++ b/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/aclitem_array.go b/aclitem_array.go index f9215a93..fe0af434 100644 --- a/aclitem_array.go +++ b/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/array.go b/array.go index e5504455..5b852ed5 100644 --- a/array.go +++ b/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/bool.go b/bool.go index 7c66a534..3a3eef48 100644 --- a/bool.go +++ b/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/bool_array.go b/bool_array.go index e20a0381..e23c27e5 100644 --- a/bool_array.go +++ b/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/box.go b/box.go index 2d098058..83df0499 100644 --- a/box.go +++ b/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/bytea.go b/bytea.go index 2ddac7da..c7117f48 100644 --- a/bytea.go +++ b/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/bytea_array.go b/bytea_array.go index 0d381693..f2842179 100644 --- a/bytea_array.go +++ b/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/cidr_array.go b/cidr_array.go index 9b7b50fa..2373da46 100644 --- a/cidr_array.go +++ b/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/circle.go b/circle.go index 8626a99d..97ecbf31 100644 --- a/circle.go +++ b/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/convert.go b/convert.go index 2b406426..5dfb738e 100644 --- a/convert.go +++ b/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/database_sql.go b/database_sql.go index 9d1cf822..969536dd 100644 --- a/database_sql.go +++ b/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/date.go b/date.go index 8e049254..f1c0d8bd 100644 --- a/date.go +++ b/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/date_array.go b/date_array.go index ef91cf3e..383945e7 100644 --- a/date_array.go +++ b/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/daterange.go b/daterange.go index bbe7b17a..47cd7e46 100644 --- a/daterange.go +++ b/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/ext/satori-uuid/uuid.go b/ext/satori-uuid/uuid.go index b7b776f9..78a90035 100644 --- a/ext/satori-uuid/uuid.go +++ b/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/ext/shopspring-numeric/decimal.go b/ext/shopspring-numeric/decimal.go index 277f3709..507a93dc 100644 --- a/ext/shopspring-numeric/decimal.go +++ b/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/float4.go b/float4.go index b24654b6..2207594a 100644 --- a/float4.go +++ b/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/float4_array.go b/float4_array.go index a35657b0..6499064b 100644 --- a/float4_array.go +++ b/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/float8.go b/float8.go index c3ecdcc2..dd34f541 100644 --- a/float8.go +++ b/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/float8_array.go b/float8_array.go index 486e3a4e..27b24836 100644 --- a/float8_array.go +++ b/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/hstore.go b/hstore.go index 09506242..347446ae 100644 --- a/hstore.go +++ b/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/hstore_array.go b/hstore_array.go index 3e5a003f..38ce457b 100644 --- a/hstore_array.go +++ b/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/inet.go b/inet.go index 7aa1df95..01fc0e5b 100644 --- a/inet.go +++ b/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/inet_array.go b/inet_array.go index 57123c1c..3ece23eb 100644 --- a/inet_array.go +++ b/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/int2.go b/int2.go index a58c3355..45bce93c 100644 --- a/int2.go +++ b/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/int2_array.go b/int2_array.go index e4993104..e939411b 100644 --- a/int2_array.go +++ b/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/int4.go b/int4.go index 6f95013b..a3499fef 100644 --- a/int4.go +++ b/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/int4_array.go b/int4_array.go index 6bc06e86..1a907d2e 100644 --- a/int4_array.go +++ b/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/int4range.go b/int4range.go index 4f27ff0d..95ad1521 100644 --- a/int4range.go +++ b/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/int8.go b/int8.go index 939c0554..d671eda7 100644 --- a/int8.go +++ b/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/int8_array.go b/int8_array.go index 4404d22a..4f3ab4dc 100644 --- a/int8_array.go +++ b/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/int8range.go b/int8range.go index 128a853f..61d860d3 100644 --- a/int8range.go +++ b/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/interval.go b/interval.go index 85d76d99..799ce53a 100644 --- a/interval.go +++ b/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/json.go b/json.go index ee00e9a4..562722aa 100644 --- a/json.go +++ b/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/jsonb.go b/jsonb.go index 9a06c1b4..c315c588 100644 --- a/jsonb.go +++ b/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/line.go b/line.go index 47f636a5..f6eadf0e 100644 --- a/line.go +++ b/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/lseg.go b/lseg.go index 44c2b63c..a9d740cf 100644 --- a/lseg.go +++ b/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/macaddr.go b/macaddr.go index e38701eb..4c6e2212 100644 --- a/macaddr.go +++ b/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/numeric.go b/numeric.go index dffb9963..fded6359 100644 --- a/numeric.go +++ b/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/numeric_array.go b/numeric_array.go index f193a2a5..6dfbe5e3 100644 --- a/numeric_array.go +++ b/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/numrange.go b/numrange.go index 00133296..aaed62ce 100644 --- a/numrange.go +++ b/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/oid.go b/oid.go index d37f4e57..59370d66 100644 --- a/oid.go +++ b/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/path.go b/path.go index 3575342d..aa0cee8e 100644 --- a/path.go +++ b/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.go b/pgtype.go index 4302a5fe..6f8e7986 100644 --- a/pgtype.go +++ b/pgtype.go @@ -1,8 +1,9 @@ package pgtype import ( - "errors" "reflect" + + "github.com/pkg/errors" ) // PostgreSQL oids for common types diff --git a/pguint32.go b/pguint32.go index 15b0f38d..e441a690 100644 --- a/pguint32.go +++ b/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/point.go b/point.go index 3d5d4e1a..3132a939 100644 --- a/point.go +++ b/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/polygon.go b/polygon.go index d0b50061..3f3d9f53 100644 --- a/polygon.go +++ b/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/qchar.go b/qchar.go index 9c40ce18..064dab1e 100644 --- a/qchar.go +++ b/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/range.go b/range.go index 76daf8cc..d870834f 100644 --- a/range.go +++ b/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/record.go b/record.go index 7c8736df..14b415c3 100644 --- a/record.go +++ b/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/text.go b/text.go index 6638c354..f05e1e89 100644 --- a/text.go +++ b/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/text_array.go b/text_array.go index dab7d36e..2609a2cc 100644 --- a/text_array.go +++ b/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/tid.go b/tid.go index d44ea3a6..21852a14 100644 --- a/tid.go +++ b/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/timestamp.go b/timestamp.go index 75c6cffa..d906f467 100644 --- a/timestamp.go +++ b/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/timestamp_array.go b/timestamp_array.go index fca9ad93..be281f2e 100644 --- a/timestamp_array.go +++ b/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/timestamptz.go b/timestamptz.go index 97b0de2a..74fe4954 100644 --- a/timestamptz.go +++ b/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/timestamptz_array.go b/timestamptz_array.go index e0866d69..086a4ef0 100644 --- a/timestamptz_array.go +++ b/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/tsrange.go b/tsrange.go index 783fb086..8a67d65e 100644 --- a/tsrange.go +++ b/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/tstzrange.go b/tstzrange.go index 8fd3fd68..b5129093 100644 --- a/tstzrange.go +++ b/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/typed_array.go.erb b/typed_array.go.erb index 01072549..7a69d0ab 100644 --- a/typed_array.go.erb +++ b/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/typed_range.go.erb b/typed_range.go.erb index 90c23991..91a5cb97 100644 --- a/typed_range.go.erb +++ b/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/uuid.go b/uuid.go index d1ab1a38..33e79536 100644 --- a/uuid.go +++ b/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/varbit.go b/varbit.go index 9a9fe1e1..dfa194d2 100644 --- a/varbit.go +++ b/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/varchar_array.go b/varchar_array.go index 95b5cfc1..fecbb2e5 100644 --- a/varchar_array.go +++ b/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.