diff --git a/aclitem.go b/aclitem.go index d2fe7529..9f6587be 100644 --- a/aclitem.go +++ b/aclitem.go @@ -2,8 +2,7 @@ package pgtype import ( "database/sql/driver" - - errors "golang.org/x/xerrors" + "fmt" ) // ACLItem is used for PostgreSQL's aclitem data type. A sample aclitem @@ -49,7 +48,7 @@ func (dst *ACLItem) Set(src interface{}) error { if originalSrc, ok := underlyingStringType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to ACLItem", value) + return fmt.Errorf("cannot convert %v to ACLItem", value) } return nil @@ -77,13 +76,13 @@ func (src *ACLItem) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *ACLItem) DecodeText(ci *ConnInfo, src []byte) error { @@ -123,7 +122,7 @@ func (dst *ACLItem) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/aclitem_array.go b/aclitem_array.go index bf7bba93..4e3be3bd 100644 --- a/aclitem_array.go +++ b/aclitem_array.go @@ -4,9 +4,8 @@ package pgtype import ( "database/sql/driver" + "fmt" "reflect" - - errors "golang.org/x/xerrors" ) type ACLItemArray struct { @@ -94,7 +93,7 @@ func (dst *ACLItemArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for ACLItemArray", src) + return fmt.Errorf("cannot find dimensions of %v for ACLItemArray", src) } if elementsLength == 0 { *dst = ACLItemArray{Status: Present} @@ -104,7 +103,7 @@ func (dst *ACLItemArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to ACLItemArray", src) + return fmt.Errorf("cannot convert %v to ACLItemArray", src) } *dst = ACLItemArray{ @@ -135,7 +134,7 @@ func (dst *ACLItemArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to ACLItemArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to ACLItemArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -153,7 +152,7 @@ func (dst *ACLItemArray) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -166,10 +165,10 @@ func (dst *ACLItemArray) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to ACLItemArray") + return 0, fmt.Errorf("cannot convert all values to ACLItemArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in ACLItemArray", err) + return 0, fmt.Errorf("%v in ACLItemArray", err) } index++ @@ -231,7 +230,7 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -246,7 +245,7 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -254,7 +253,7 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *ACLItemArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -270,7 +269,7 @@ func (src *ACLItemArray) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -288,14 +287,14 @@ func (src *ACLItemArray) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from ACLItemArray") + return 0, fmt.Errorf("cannot assign all values from ACLItemArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from ACLItemArray") + return 0, fmt.Errorf("cannot assign all values from ACLItemArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -412,7 +411,7 @@ func (dst *ACLItemArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/array.go b/array.go index 4e22166e..3d5930c1 100644 --- a/array.go +++ b/array.go @@ -3,6 +3,7 @@ package pgtype import ( "bytes" "encoding/binary" + "fmt" "io" "reflect" "strconv" @@ -10,7 +11,6 @@ import ( "unicode" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) // Information on the internals of PostgreSQL arrays can be found in @@ -30,7 +30,7 @@ type ArrayDimension struct { func (dst *ArrayHeader) DecodeBinary(ci *ConnInfo, src []byte) (int, error) { if len(src) < 12 { - return 0, errors.Errorf("array header too short: %d", len(src)) + return 0, fmt.Errorf("array header too short: %d", len(src)) } rp := 0 @@ -48,7 +48,7 @@ func (dst *ArrayHeader) DecodeBinary(ci *ConnInfo, src []byte) (int, error) { dst.Dimensions = make([]ArrayDimension, numDims) } if len(src) < 12+numDims*8 { - return 0, errors.Errorf("array header too short for %d dimensions: %d", numDims, len(src)) + return 0, fmt.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:])) @@ -95,7 +95,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { r, _, err := buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } var explicitDimensions []ArrayDimension @@ -107,41 +107,41 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { for { r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } if r == '=' { break } else if r != '[' { - return nil, errors.Errorf("invalid array, expected '[' or '=' got %v", r) + return nil, fmt.Errorf("invalid array, expected '[' or '=' got %v", r) } lower, err := arrayParseInteger(buf) if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } if r != ':' { - return nil, errors.Errorf("invalid array, expected ':' got %v", r) + return nil, fmt.Errorf("invalid array, expected ':' got %v", r) } upper, err := arrayParseInteger(buf) if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } if r != ']' { - return nil, errors.Errorf("invalid array, expected ']' got %v", r) + return nil, fmt.Errorf("invalid array, expected ']' got %v", r) } explicitDimensions = append(explicitDimensions, ArrayDimension{LowerBound: lower, Length: upper - lower + 1}) @@ -149,12 +149,12 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } } if r != '{' { - return nil, errors.Errorf("invalid array, expected '{': %v", err) + return nil, fmt.Errorf("invalid array, expected '{': %v", err) } implicitDimensions := []ArrayDimension{{LowerBound: 1, Length: 0}} @@ -163,7 +163,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { for { r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } if r == '{' { @@ -180,7 +180,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { for { r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid array: %v", err) + return nil, fmt.Errorf("invalid array: %v", err) } switch r { @@ -199,7 +199,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { buf.UnreadRune() value, quoted, err := arrayParseValue(buf) if err != nil { - return nil, errors.Errorf("invalid array value: %v", err) + return nil, fmt.Errorf("invalid array value: %v", err) } if currentDim == counterDim { implicitDimensions[currentDim].Length++ @@ -216,7 +216,7 @@ func ParseUntypedTextArray(src string) (*UntypedTextArray, error) { skipWhitespace(buf) if buf.Len() > 0 { - return nil, errors.Errorf("unexpected trailing data: %v", buf.String()) + return nil, fmt.Errorf("unexpected trailing data: %v", buf.String()) } if len(dst.Elements) == 0 { diff --git a/array_type.go b/array_type.go index 04b8710c..1bd0244b 100644 --- a/array_type.go +++ b/array_type.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) // ArrayType represents an array type. While it implements Value, this is only in service of its type conversion duties @@ -58,7 +58,7 @@ func (dst *ArrayType) Set(src interface{}) error { sliceVal := reflect.ValueOf(src) if sliceVal.Kind() != reflect.Slice { - return errors.Errorf("cannot set non-slice") + return fmt.Errorf("cannot set non-slice") } if sliceVal.IsNil() { @@ -100,14 +100,14 @@ func (dst ArrayType) Get() interface{} { func (src *ArrayType) AssignTo(dst interface{}) error { ptrSlice := reflect.ValueOf(dst) if ptrSlice.Kind() != reflect.Ptr { - return errors.Errorf("cannot assign to non-pointer") + return fmt.Errorf("cannot assign to non-pointer") } sliceVal := ptrSlice.Elem() sliceType := sliceVal.Type() if sliceType.Kind() != reflect.Slice { - return errors.Errorf("cannot assign to pointer to non-slice") + return fmt.Errorf("cannot assign to pointer to non-slice") } switch src.status { @@ -132,7 +132,7 @@ func (src *ArrayType) AssignTo(dst interface{}) error { return nil } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *ArrayType) DecodeText(ci *ConnInfo, src []byte) error { @@ -336,7 +336,7 @@ func (dst *ArrayType) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/bool.go b/bool.go index 9ec5097f..676c8e5d 100644 --- a/bool.go +++ b/bool.go @@ -3,9 +3,8 @@ package pgtype import ( "database/sql/driver" "encoding/json" + "fmt" "strconv" - - errors "golang.org/x/xerrors" ) type Bool struct { @@ -51,7 +50,7 @@ func (dst *Bool) Set(src interface{}) error { if originalSrc, ok := underlyingBoolType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Bool", value) + return fmt.Errorf("cannot convert %v to Bool", value) } return nil @@ -79,13 +78,13 @@ func (src *Bool) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *Bool) DecodeText(ci *ConnInfo, src []byte) error { @@ -95,7 +94,7 @@ func (dst *Bool) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) != 1 { - return errors.Errorf("invalid length for bool: %v", len(src)) + return fmt.Errorf("invalid length for bool: %v", len(src)) } *dst = Bool{Bool: src[0] == 't', Status: Present} @@ -109,7 +108,7 @@ func (dst *Bool) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 1 { - return errors.Errorf("invalid length for bool: %v", len(src)) + return fmt.Errorf("invalid length for bool: %v", len(src)) } *dst = Bool{Bool: src[0] == 1, Status: Present} @@ -169,7 +168,7 @@ func (dst *Bool) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/bool_array.go b/bool_array.go index 2659321e..6558d971 100644 --- a/bool_array.go +++ b/bool_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type BoolArray struct { @@ -96,7 +96,7 @@ func (dst *BoolArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for BoolArray", src) + return fmt.Errorf("cannot find dimensions of %v for BoolArray", src) } if elementsLength == 0 { *dst = BoolArray{Status: Present} @@ -106,7 +106,7 @@ func (dst *BoolArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to BoolArray", src) + return fmt.Errorf("cannot convert %v to BoolArray", src) } *dst = BoolArray{ @@ -137,7 +137,7 @@ func (dst *BoolArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to BoolArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to BoolArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -155,7 +155,7 @@ func (dst *BoolArray) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -168,10 +168,10 @@ func (dst *BoolArray) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to BoolArray") + return 0, fmt.Errorf("cannot convert all values to BoolArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in BoolArray", err) + return 0, fmt.Errorf("%v in BoolArray", err) } index++ @@ -233,7 +233,7 @@ func (src *BoolArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -248,7 +248,7 @@ func (src *BoolArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -256,7 +256,7 @@ func (src *BoolArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *BoolArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -272,7 +272,7 @@ func (src *BoolArray) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -290,14 +290,14 @@ func (src *BoolArray) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from BoolArray") + return 0, fmt.Errorf("cannot assign all values from BoolArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from BoolArray") + return 0, fmt.Errorf("cannot assign all values from BoolArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -456,7 +456,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, errors.Errorf("unable to find oid for type name %v", "bool") + return nil, fmt.Errorf("unable to find oid for type name %v", "bool") } for i := range src.Elements { @@ -500,7 +500,7 @@ func (dst *BoolArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/box.go b/box.go index 75d50f98..27fb829e 100644 --- a/box.go +++ b/box.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Box struct { @@ -18,7 +17,7 @@ type Box struct { } func (dst *Box) Set(src interface{}) error { - return errors.Errorf("cannot convert %v to Box", src) + return fmt.Errorf("cannot convert %v to Box", src) } func (dst Box) Get() interface{} { @@ -33,7 +32,7 @@ func (dst Box) Get() interface{} { } func (src *Box) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Box) DecodeText(ci *ConnInfo, src []byte) error { @@ -43,7 +42,7 @@ func (dst *Box) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 11 { - return errors.Errorf("invalid length for Box: %v", len(src)) + return fmt.Errorf("invalid length for Box: %v", len(src)) } str := string(src[1:]) @@ -90,7 +89,7 @@ func (dst *Box) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 32 { - return errors.Errorf("invalid length for Box: %v", len(src)) + return fmt.Errorf("invalid length for Box: %v", len(src)) } x1 := binary.BigEndian.Uint64(src) @@ -157,7 +156,7 @@ func (dst *Box) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/bpchar_array.go b/bpchar_array.go index d48b2b53..8e792214 100644 --- a/bpchar_array.go +++ b/bpchar_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type BPCharArray struct { @@ -96,7 +96,7 @@ func (dst *BPCharArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for BPCharArray", src) + return fmt.Errorf("cannot find dimensions of %v for BPCharArray", src) } if elementsLength == 0 { *dst = BPCharArray{Status: Present} @@ -106,7 +106,7 @@ func (dst *BPCharArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to BPCharArray", src) + return fmt.Errorf("cannot convert %v to BPCharArray", src) } *dst = BPCharArray{ @@ -137,7 +137,7 @@ func (dst *BPCharArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to BPCharArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to BPCharArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -155,7 +155,7 @@ func (dst *BPCharArray) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -168,10 +168,10 @@ func (dst *BPCharArray) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to BPCharArray") + return 0, fmt.Errorf("cannot convert all values to BPCharArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in BPCharArray", err) + return 0, fmt.Errorf("%v in BPCharArray", err) } index++ @@ -233,7 +233,7 @@ func (src *BPCharArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -248,7 +248,7 @@ func (src *BPCharArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -256,7 +256,7 @@ func (src *BPCharArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *BPCharArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -272,7 +272,7 @@ func (src *BPCharArray) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -290,14 +290,14 @@ func (src *BPCharArray) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from BPCharArray") + return 0, fmt.Errorf("cannot assign all values from BPCharArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from BPCharArray") + return 0, fmt.Errorf("cannot assign all values from BPCharArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -456,7 +456,7 @@ func (src BPCharArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("bpchar"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "bpchar") + return nil, fmt.Errorf("unable to find oid for type name %v", "bpchar") } for i := range src.Elements { @@ -500,7 +500,7 @@ func (dst *BPCharArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/bytea.go b/bytea.go index b9e4d15a..67eba350 100644 --- a/bytea.go +++ b/bytea.go @@ -3,8 +3,7 @@ package pgtype import ( "database/sql/driver" "encoding/hex" - - errors "golang.org/x/xerrors" + "fmt" ) type Bytea struct { @@ -36,7 +35,7 @@ func (dst *Bytea) Set(src interface{}) error { if originalSrc, ok := underlyingBytesType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Bytea", value) + return fmt.Errorf("cannot convert %v to Bytea", value) } return nil @@ -66,13 +65,13 @@ func (src *Bytea) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } // DecodeText only supports the hex format. This has been the default since @@ -84,7 +83,7 @@ func (dst *Bytea) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 2 || src[0] != '\\' || src[1] != 'x' { - return errors.Errorf("invalid hex format") + return fmt.Errorf("invalid hex format") } buf := make([]byte, (len(src)-2)/2) @@ -148,7 +147,7 @@ func (dst *Bytea) Scan(src interface{}) error { return nil } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/bytea_array.go b/bytea_array.go index 14d8afad..69d1ceb9 100644 --- a/bytea_array.go +++ b/bytea_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type ByteaArray struct { @@ -77,7 +77,7 @@ func (dst *ByteaArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for ByteaArray", src) + return fmt.Errorf("cannot find dimensions of %v for ByteaArray", src) } if elementsLength == 0 { *dst = ByteaArray{Status: Present} @@ -87,7 +87,7 @@ func (dst *ByteaArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to ByteaArray", src) + return fmt.Errorf("cannot convert %v to ByteaArray", src) } *dst = ByteaArray{ @@ -118,7 +118,7 @@ func (dst *ByteaArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to ByteaArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to ByteaArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -136,7 +136,7 @@ func (dst *ByteaArray) setRecursive(value reflect.Value, index, dimension int) ( valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -149,10 +149,10 @@ func (dst *ByteaArray) setRecursive(value reflect.Value, index, dimension int) ( return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to ByteaArray") + return 0, fmt.Errorf("cannot convert all values to ByteaArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in ByteaArray", err) + return 0, fmt.Errorf("%v in ByteaArray", err) } index++ @@ -205,7 +205,7 @@ func (src *ByteaArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -220,7 +220,7 @@ func (src *ByteaArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -228,7 +228,7 @@ func (src *ByteaArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *ByteaArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -244,7 +244,7 @@ func (src *ByteaArray) assignToRecursive(value reflect.Value, index, dimension i if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -262,14 +262,14 @@ func (src *ByteaArray) assignToRecursive(value reflect.Value, index, dimension i return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from ByteaArray") + return 0, fmt.Errorf("cannot assign all values from ByteaArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from ByteaArray") + return 0, fmt.Errorf("cannot assign all values from ByteaArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -428,7 +428,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, errors.Errorf("unable to find oid for type name %v", "bytea") + return nil, fmt.Errorf("unable to find oid for type name %v", "bytea") } for i := range src.Elements { @@ -472,7 +472,7 @@ func (dst *ByteaArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/cidr_array.go b/cidr_array.go index 3ac1b183..783c599c 100644 --- a/cidr_array.go +++ b/cidr_array.go @@ -5,11 +5,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "net" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type CIDRArray struct { @@ -116,7 +116,7 @@ func (dst *CIDRArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for CIDRArray", src) + return fmt.Errorf("cannot find dimensions of %v for CIDRArray", src) } if elementsLength == 0 { *dst = CIDRArray{Status: Present} @@ -126,7 +126,7 @@ func (dst *CIDRArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to CIDRArray", src) + return fmt.Errorf("cannot convert %v to CIDRArray", src) } *dst = CIDRArray{ @@ -157,7 +157,7 @@ func (dst *CIDRArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to CIDRArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to CIDRArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -175,7 +175,7 @@ func (dst *CIDRArray) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -188,10 +188,10 @@ func (dst *CIDRArray) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to CIDRArray") + return 0, fmt.Errorf("cannot convert all values to CIDRArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in CIDRArray", err) + return 0, fmt.Errorf("%v in CIDRArray", err) } index++ @@ -262,7 +262,7 @@ func (src *CIDRArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -277,7 +277,7 @@ func (src *CIDRArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -285,7 +285,7 @@ func (src *CIDRArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *CIDRArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -301,7 +301,7 @@ func (src *CIDRArray) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -319,14 +319,14 @@ func (src *CIDRArray) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from CIDRArray") + return 0, fmt.Errorf("cannot assign all values from CIDRArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from CIDRArray") + return 0, fmt.Errorf("cannot assign all values from CIDRArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -485,7 +485,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, errors.Errorf("unable to find oid for type name %v", "cidr") + return nil, fmt.Errorf("unable to find oid for type name %v", "cidr") } for i := range src.Elements { @@ -529,7 +529,7 @@ func (dst *CIDRArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/circle.go b/circle.go index d3f8b38a..4279650e 100644 --- a/circle.go +++ b/circle.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Circle struct { @@ -19,7 +18,7 @@ type Circle struct { } func (dst *Circle) Set(src interface{}) error { - return errors.Errorf("cannot convert %v to Circle", src) + return fmt.Errorf("cannot convert %v to Circle", src) } func (dst Circle) Get() interface{} { @@ -34,7 +33,7 @@ func (dst Circle) Get() interface{} { } func (src *Circle) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Circle) DecodeText(ci *ConnInfo, src []byte) error { @@ -44,7 +43,7 @@ func (dst *Circle) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 9 { - return errors.Errorf("invalid length for Circle: %v", len(src)) + return fmt.Errorf("invalid length for Circle: %v", len(src)) } str := string(src[2:]) @@ -80,7 +79,7 @@ func (dst *Circle) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 24 { - return errors.Errorf("invalid length for Circle: %v", len(src)) + return fmt.Errorf("invalid length for Circle: %v", len(src)) } x := binary.BigEndian.Uint64(src) @@ -142,7 +141,7 @@ func (dst *Circle) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/composite_fields.go b/composite_fields.go index af7bab1e..b6d09fcf 100644 --- a/composite_fields.go +++ b/composite_fields.go @@ -1,8 +1,6 @@ package pgtype -import ( - errors "golang.org/x/xerrors" -) +import "fmt" // CompositeFields scans the fields of a composite type into the elements of the CompositeFields value. To scan a // nullable value use a *CompositeFields. It will be set to nil in case of null. @@ -13,11 +11,11 @@ type CompositeFields []interface{} func (cf CompositeFields) DecodeBinary(ci *ConnInfo, src []byte) error { if len(cf) == 0 { - return errors.Errorf("cannot decode into empty CompositeFields") + return fmt.Errorf("cannot decode into empty CompositeFields") } if src == nil { - return errors.Errorf("cannot decode unexpected null into CompositeFields") + return fmt.Errorf("cannot decode unexpected null into CompositeFields") } scanner := NewCompositeBinaryScanner(ci, src) @@ -35,11 +33,11 @@ func (cf CompositeFields) DecodeBinary(ci *ConnInfo, src []byte) error { func (cf CompositeFields) DecodeText(ci *ConnInfo, src []byte) error { if len(cf) == 0 { - return errors.Errorf("cannot decode into empty CompositeFields") + return fmt.Errorf("cannot decode into empty CompositeFields") } if src == nil { - return errors.Errorf("cannot decode unexpected null into CompositeFields") + return fmt.Errorf("cannot decode unexpected null into CompositeFields") } scanner := NewCompositeTextScanner(ci, src) @@ -87,7 +85,7 @@ func (cf CompositeFields) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) for _, f := range cf { dt, ok := ci.DataTypeForValue(f) if !ok { - return nil, errors.Errorf("Unknown OID for %#v", f) + return nil, fmt.Errorf("Unknown OID for %#v", f) } if binaryEncoder, ok := f.(BinaryEncoder); ok { @@ -100,7 +98,7 @@ func (cf CompositeFields) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) if binaryEncoder, ok := dt.Value.(BinaryEncoder); ok { b.AppendEncoder(dt.OID, binaryEncoder) } else { - return nil, errors.Errorf("Cannot encode binary format for %v", f) + return nil, fmt.Errorf("Cannot encode binary format for %v", f) } } } diff --git a/composite_type.go b/composite_type.go index cbe0a245..7c8dbcd5 100644 --- a/composite_type.go +++ b/composite_type.go @@ -2,11 +2,12 @@ package pgtype import ( "encoding/binary" + "errors" + "fmt" "reflect" "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type CompositeTypeField struct { @@ -31,13 +32,13 @@ func NewCompositeType(typeName string, fields []CompositeTypeField, ci *ConnInfo for i := range fields { dt, ok := ci.DataTypeForOID(fields[i].OID) if !ok { - return nil, errors.Errorf("no data type registered for oid: %d", fields[i].OID) + return nil, fmt.Errorf("no data type registered for oid: %d", fields[i].OID) } value := NewValue(dt.Value) valueTranscoder, ok := value.(ValueTranscoder) if !ok { - return nil, errors.Errorf("data type for oid does not implement ValueTranscoder: %d", fields[i].OID) + return nil, fmt.Errorf("data type for oid does not implement ValueTranscoder: %d", fields[i].OID) } valueTranscoders[i] = valueTranscoder @@ -102,7 +103,7 @@ func (dst *CompositeType) Set(src interface{}) error { switch value := src.(type) { case []interface{}: if len(value) != len(dst.valueTranscoders) { - return errors.Errorf("Number of fields don't match. CompositeType has %d fields", len(dst.valueTranscoders)) + return fmt.Errorf("Number of fields don't match. CompositeType has %d fields", len(dst.valueTranscoders)) } for i, v := range value { if err := dst.valueTranscoders[i].Set(v); err != nil { @@ -117,7 +118,7 @@ func (dst *CompositeType) Set(src interface{}) error { } return dst.Set(*value) default: - return errors.Errorf("Can not convert %v to Composite", src) + return fmt.Errorf("Can not convert %v to Composite", src) } return nil @@ -130,7 +131,7 @@ func (src CompositeType) AssignTo(dst interface{}) error { switch v := dst.(type) { case []interface{}: if len(v) != len(src.valueTranscoders) { - return errors.Errorf("Number of fields don't match. CompositeType has %d fields", len(src.valueTranscoders)) + return fmt.Errorf("Number of fields don't match. CompositeType has %d fields", len(src.valueTranscoders)) } for i := range src.valueTranscoders { if v[i] == nil { @@ -139,7 +140,7 @@ func (src CompositeType) AssignTo(dst interface{}) error { err := assignToOrSet(src.valueTranscoders[i], v[i]) if err != nil { - return errors.Errorf("unable to assign to dst[%d]: %v", i, err) + return fmt.Errorf("unable to assign to dst[%d]: %v", i, err) } } return nil @@ -153,12 +154,12 @@ func (src CompositeType) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func assignToOrSet(src Value, dst interface{}) error { @@ -210,7 +211,7 @@ func (src CompositeType) assignToPtrStruct(dst interface{}) (bool, error) { for i := range exportedFields { err := assignToOrSet(src.valueTranscoders[i], dstElemValue.Field(exportedFields[i]).Addr().Interface()) if err != nil { - return true, errors.Errorf("unable to assign to field %s: %v", dstElemType.Field(exportedFields[i]).Name, err) + return true, fmt.Errorf("unable to assign to field %s: %v", dstElemType.Field(exportedFields[i]).Name, err) } } @@ -310,7 +311,7 @@ type CompositeBinaryScanner struct { func NewCompositeBinaryScanner(ci *ConnInfo, src []byte) *CompositeBinaryScanner { rp := 0 if len(src[rp:]) < 4 { - return &CompositeBinaryScanner{err: errors.Errorf("Record incomplete %v", src)} + return &CompositeBinaryScanner{err: fmt.Errorf("Record incomplete %v", src)} } fieldCount := int32(binary.BigEndian.Uint32(src[rp:])) @@ -362,7 +363,7 @@ func (cfs *CompositeBinaryScanner) Next() bool { } if len(cfs.src[cfs.rp:]) < 8 { - cfs.err = errors.Errorf("Record incomplete %v", cfs.src) + cfs.err = fmt.Errorf("Record incomplete %v", cfs.src) return false } cfs.fieldOID = binary.BigEndian.Uint32(cfs.src[cfs.rp:]) @@ -373,7 +374,7 @@ func (cfs *CompositeBinaryScanner) Next() bool { if fieldLen >= 0 { if len(cfs.src[cfs.rp:]) < fieldLen { - cfs.err = errors.Errorf("Record incomplete rp=%d src=%v", cfs.rp, cfs.src) + cfs.err = fmt.Errorf("Record incomplete rp=%d src=%v", cfs.rp, cfs.src) return false } cfs.fieldBytes = cfs.src[cfs.rp : cfs.rp+fieldLen] @@ -416,15 +417,15 @@ type CompositeTextScanner struct { // NewCompositeTextScanner a scanner over a text encoded composite value. func NewCompositeTextScanner(ci *ConnInfo, src []byte) *CompositeTextScanner { if len(src) < 2 { - return &CompositeTextScanner{err: errors.Errorf("Record incomplete %v", src)} + return &CompositeTextScanner{err: fmt.Errorf("Record incomplete %v", src)} } if src[0] != '(' { - return &CompositeTextScanner{err: errors.Errorf("composite text format must start with '('")} + return &CompositeTextScanner{err: fmt.Errorf("composite text format must start with '('")} } if src[len(src)-1] != ')' { - return &CompositeTextScanner{err: errors.Errorf("composite text format must end with ')'")} + return &CompositeTextScanner{err: fmt.Errorf("composite text format must end with ')'")} } return &CompositeTextScanner{ @@ -543,7 +544,7 @@ func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field interface{}) { dt, ok := b.ci.DataTypeForOID(oid) if !ok { - b.err = errors.Errorf("unknown data type for OID: %d", oid) + b.err = fmt.Errorf("unknown data type for OID: %d", oid) return } @@ -555,7 +556,7 @@ func (b *CompositeBinaryBuilder) AppendValue(oid uint32, field interface{}) { binaryEncoder, ok := dt.Value.(BinaryEncoder) if !ok { - b.err = errors.Errorf("unable to encode binary for OID: %d", oid) + b.err = fmt.Errorf("unable to encode binary for OID: %d", oid) return } @@ -618,7 +619,7 @@ func (b *CompositeTextBuilder) AppendValue(field interface{}) { dt, ok := b.ci.DataTypeForValue(field) if !ok { - b.err = errors.Errorf("unknown data type for field: %v", field) + b.err = fmt.Errorf("unknown data type for field: %v", field) return } @@ -630,7 +631,7 @@ func (b *CompositeTextBuilder) AppendValue(field interface{}) { textEncoder, ok := dt.Value.(TextEncoder) if !ok { - b.err = errors.Errorf("unable to encode text for value: %v", field) + b.err = fmt.Errorf("unable to encode text for value: %v", field) return } diff --git a/convert.go b/convert.go index 193f771f..8ae599b9 100644 --- a/convert.go +++ b/convert.go @@ -2,11 +2,10 @@ package pgtype import ( "database/sql" + "fmt" "math" "reflect" "time" - - errors "golang.org/x/xerrors" ) const maxUint = ^uint(0) @@ -212,70 +211,70 @@ func int64AssignTo(srcVal int64, srcStatus Status, dst interface{}) error { switch v := dst.(type) { case *int: if srcVal < int64(minInt) { - return errors.Errorf("%d is less than minimum value for int", srcVal) + return fmt.Errorf("%d is less than minimum value for int", srcVal) } else if srcVal > int64(maxInt) { - return errors.Errorf("%d is greater than maximum value for int", srcVal) + return fmt.Errorf("%d is greater than maximum value for int", srcVal) } *v = int(srcVal) case *int8: if srcVal < math.MinInt8 { - return errors.Errorf("%d is less than minimum value for int8", srcVal) + return fmt.Errorf("%d is less than minimum value for int8", srcVal) } else if srcVal > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for int8", srcVal) + return fmt.Errorf("%d is greater than maximum value for int8", srcVal) } *v = int8(srcVal) case *int16: if srcVal < math.MinInt16 { - return errors.Errorf("%d is less than minimum value for int16", srcVal) + return fmt.Errorf("%d is less than minimum value for int16", srcVal) } else if srcVal > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for int16", srcVal) + return fmt.Errorf("%d is greater than maximum value for int16", srcVal) } *v = int16(srcVal) case *int32: if srcVal < math.MinInt32 { - return errors.Errorf("%d is less than minimum value for int32", srcVal) + return fmt.Errorf("%d is less than minimum value for int32", srcVal) } else if srcVal > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for int32", srcVal) + return fmt.Errorf("%d is greater than maximum value for int32", srcVal) } *v = int32(srcVal) case *int64: if srcVal < math.MinInt64 { - return errors.Errorf("%d is less than minimum value for int64", srcVal) + return fmt.Errorf("%d is less than minimum value for int64", srcVal) } else if srcVal > math.MaxInt64 { - return errors.Errorf("%d is greater than maximum value for int64", srcVal) + return fmt.Errorf("%d is greater than maximum value for int64", srcVal) } *v = int64(srcVal) case *uint: if srcVal < 0 { - return errors.Errorf("%d is less than zero for uint", srcVal) + return fmt.Errorf("%d is less than zero for uint", srcVal) } else if uint64(srcVal) > uint64(maxUint) { - return errors.Errorf("%d is greater than maximum value for uint", srcVal) + return fmt.Errorf("%d is greater than maximum value for uint", srcVal) } *v = uint(srcVal) case *uint8: if srcVal < 0 { - return errors.Errorf("%d is less than zero for uint8", srcVal) + return fmt.Errorf("%d is less than zero for uint8", srcVal) } else if srcVal > math.MaxUint8 { - return errors.Errorf("%d is greater than maximum value for uint8", srcVal) + return fmt.Errorf("%d is greater than maximum value for uint8", srcVal) } *v = uint8(srcVal) case *uint16: if srcVal < 0 { - return errors.Errorf("%d is less than zero for uint32", srcVal) + return fmt.Errorf("%d is less than zero for uint32", srcVal) } else if srcVal > math.MaxUint16 { - return errors.Errorf("%d is greater than maximum value for uint16", srcVal) + return fmt.Errorf("%d is greater than maximum value for uint16", srcVal) } *v = uint16(srcVal) case *uint32: if srcVal < 0 { - return errors.Errorf("%d is less than zero for uint32", srcVal) + return fmt.Errorf("%d is less than zero for uint32", srcVal) } else if srcVal > math.MaxUint32 { - return errors.Errorf("%d is greater than maximum value for uint32", srcVal) + return fmt.Errorf("%d is greater than maximum value for uint32", srcVal) } *v = uint32(srcVal) case *uint64: if srcVal < 0 { - return errors.Errorf("%d is less than zero for uint64", srcVal) + return fmt.Errorf("%d is less than zero for uint64", srcVal) } *v = uint64(srcVal) case sql.Scanner: @@ -293,22 +292,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 errors.Errorf("cannot put %d into %T", srcVal, dst) + return fmt.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 errors.Errorf("%d is less than zero for %T", srcVal, dst) + return fmt.Errorf("%d is less than zero for %T", srcVal, dst) } if el.OverflowUint(uint64(srcVal)) { - return errors.Errorf("cannot put %d into %T", srcVal, dst) + return fmt.Errorf("cannot put %d into %T", srcVal, dst) } el.SetUint(uint64(srcVal)) return nil } } - return errors.Errorf("cannot assign %v into %T", srcVal, dst) + return fmt.Errorf("cannot assign %v into %T", srcVal, dst) } return nil } @@ -322,7 +321,7 @@ func int64AssignTo(srcVal int64, srcStatus Status, dst interface{}) error { } } - return errors.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) + return fmt.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) } func float64AssignTo(srcVal float64, srcStatus Status, dst interface{}) error { @@ -350,7 +349,7 @@ func float64AssignTo(srcVal float64, srcStatus Status, dst interface{}) error { } } } - return errors.Errorf("cannot assign %v into %T", srcVal, dst) + return fmt.Errorf("cannot assign %v into %T", srcVal, dst) } return nil } @@ -364,7 +363,7 @@ func float64AssignTo(srcVal float64, srcStatus Status, dst interface{}) error { } } - return errors.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) + return fmt.Errorf("cannot assign %v %v into %T", srcVal, srcStatus, dst) } func NullAssignTo(dst interface{}) error { diff --git a/custom_composite_test.go b/custom_composite_test.go index 296fcc90..9ca8dd5e 100644 --- a/custom_composite_test.go +++ b/custom_composite_test.go @@ -2,12 +2,12 @@ package pgtype_test import ( "context" + "errors" "fmt" "os" "github.com/jackc/pgtype" pgx "github.com/jackc/pgx/v4" - errors "golang.org/x/xerrors" ) type MyType struct { diff --git a/database_sql.go b/database_sql.go index f54a750d..9d1cf822 100644 --- a/database_sql.go +++ b/database_sql.go @@ -2,8 +2,7 @@ package pgtype import ( "database/sql/driver" - - errors "golang.org/x/xerrors" + "errors" ) func DatabaseSQLValue(ci *ConnInfo, src Value) (interface{}, error) { diff --git a/date.go b/date.go index 59e225df..e8d21a78 100644 --- a/date.go +++ b/date.go @@ -4,10 +4,10 @@ import ( "database/sql/driver" "encoding/binary" "encoding/json" + "fmt" "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Date struct { @@ -55,7 +55,7 @@ func (dst *Date) Set(src interface{}) error { if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Date", value) + return fmt.Errorf("cannot convert %v to Date", value) } return nil @@ -81,7 +81,7 @@ func (src *Date) AssignTo(dst interface{}) error { switch v := dst.(type) { case *time.Time: if src.InfinityModifier != None { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } *v = src.Time return nil @@ -89,13 +89,13 @@ func (src *Date) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *Date) DecodeText(ci *ConnInfo, src []byte) error { @@ -129,7 +129,7 @@ func (dst *Date) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 4 { - return errors.Errorf("invalid length for date: %v", len(src)) + return fmt.Errorf("invalid length for date: %v", len(src)) } dayOffset := int32(binary.BigEndian.Uint32(src)) @@ -213,7 +213,7 @@ func (dst *Date) Scan(src interface{}) error { return nil } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/date_array.go b/date_array.go index 0c623b8f..24152fa0 100644 --- a/date_array.go +++ b/date_array.go @@ -5,11 +5,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type DateArray struct { @@ -97,7 +97,7 @@ func (dst *DateArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for DateArray", src) + return fmt.Errorf("cannot find dimensions of %v for DateArray", src) } if elementsLength == 0 { *dst = DateArray{Status: Present} @@ -107,7 +107,7 @@ func (dst *DateArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to DateArray", src) + return fmt.Errorf("cannot convert %v to DateArray", src) } *dst = DateArray{ @@ -138,7 +138,7 @@ func (dst *DateArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to DateArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to DateArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -156,7 +156,7 @@ func (dst *DateArray) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -169,10 +169,10 @@ func (dst *DateArray) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to DateArray") + return 0, fmt.Errorf("cannot convert all values to DateArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in DateArray", err) + return 0, fmt.Errorf("%v in DateArray", err) } index++ @@ -234,7 +234,7 @@ func (src *DateArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -249,7 +249,7 @@ func (src *DateArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -257,7 +257,7 @@ func (src *DateArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *DateArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -273,7 +273,7 @@ func (src *DateArray) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -291,14 +291,14 @@ func (src *DateArray) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from DateArray") + return 0, fmt.Errorf("cannot assign all values from DateArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from DateArray") + return 0, fmt.Errorf("cannot assign all values from DateArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -457,7 +457,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, errors.Errorf("unable to find oid for type name %v", "date") + return nil, fmt.Errorf("unable to find oid for type name %v", "date") } for i := range src.Elements { @@ -501,7 +501,7 @@ func (dst *DateArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/daterange.go b/daterange.go index 7b9af795..63164a5a 100644 --- a/daterange.go +++ b/daterange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" + "fmt" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Daterange struct { @@ -30,7 +30,7 @@ func (dst *Daterange) Set(src interface{}) error { case string: return dst.DecodeText(nil, []byte(value)) default: - return errors.Errorf("cannot convert %v to Daterange", src) + return fmt.Errorf("cannot convert %v to Daterange", src) } return nil @@ -48,7 +48,7 @@ func (dst Daterange) Get() interface{} { } func (src *Daterange) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Daterange) DecodeText(ci *ConnInfo, src []byte) error { @@ -137,7 +137,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) + return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -147,7 +147,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -158,7 +158,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -168,7 +168,7 @@ func (src Daterange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) + return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -192,7 +192,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) + return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -202,7 +202,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) + return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -218,7 +218,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -233,7 +233,7 @@ func (src Daterange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -258,7 +258,7 @@ func (dst *Daterange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/enum_array.go b/enum_array.go index cf7c7066..59b5a3ed 100644 --- a/enum_array.go +++ b/enum_array.go @@ -4,9 +4,8 @@ package pgtype import ( "database/sql/driver" + "fmt" "reflect" - - errors "golang.org/x/xerrors" ) type EnumArray struct { @@ -94,7 +93,7 @@ func (dst *EnumArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for EnumArray", src) + return fmt.Errorf("cannot find dimensions of %v for EnumArray", src) } if elementsLength == 0 { *dst = EnumArray{Status: Present} @@ -104,7 +103,7 @@ func (dst *EnumArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to EnumArray", src) + return fmt.Errorf("cannot convert %v to EnumArray", src) } *dst = EnumArray{ @@ -135,7 +134,7 @@ func (dst *EnumArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to EnumArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to EnumArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -153,7 +152,7 @@ func (dst *EnumArray) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -166,10 +165,10 @@ func (dst *EnumArray) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to EnumArray") + return 0, fmt.Errorf("cannot convert all values to EnumArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in EnumArray", err) + return 0, fmt.Errorf("%v in EnumArray", err) } index++ @@ -231,7 +230,7 @@ func (src *EnumArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -246,7 +245,7 @@ func (src *EnumArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -254,7 +253,7 @@ func (src *EnumArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *EnumArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -270,7 +269,7 @@ func (src *EnumArray) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -288,14 +287,14 @@ func (src *EnumArray) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from EnumArray") + return 0, fmt.Errorf("cannot assign all values from EnumArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from EnumArray") + return 0, fmt.Errorf("cannot assign all values from EnumArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -412,7 +411,7 @@ func (dst *EnumArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/enum_type.go b/enum_type.go index d3a1df5c..d340320f 100644 --- a/enum_type.go +++ b/enum_type.go @@ -1,6 +1,6 @@ package pgtype -import errors "golang.org/x/xerrors" +import "fmt" // EnumType represents a enum type. While it implements Value, this is only in service of its type conversion duties // when registered as a data type in a ConnType. It should not be used directly as a Value. @@ -79,7 +79,7 @@ func (dst *EnumType) Set(src interface{}) error { if originalSrc, ok := underlyingStringType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to enum %s", value, dst.typeName) + return fmt.Errorf("cannot convert %v to enum %s", value, dst.typeName) } return nil @@ -111,13 +111,13 @@ func (src *EnumType) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (EnumType) PreferredResultFormat() int16 { diff --git a/ext/gofrs-uuid/uuid.go b/ext/gofrs-uuid/uuid.go index e29933c9..a5e0a3c3 100644 --- a/ext/gofrs-uuid/uuid.go +++ b/ext/gofrs-uuid/uuid.go @@ -2,8 +2,8 @@ package uuid import ( "database/sql/driver" - - errors "golang.org/x/xerrors" + "errors" + "fmt" "github.com/gofrs/uuid" "github.com/jackc/pgtype" @@ -37,7 +37,7 @@ func (dst *UUID) Set(src interface{}) error { *dst = UUID{UUID: uuid.UUID(value), Status: pgtype.Present} case []byte: if len(value) != 16 { - return errors.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) + return fmt.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) } *dst = UUID{Status: pgtype.Present} copy(dst.UUID[:], value) @@ -51,7 +51,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 errors.Errorf("cannot convert %v to UUID", value) + return fmt.Errorf("cannot convert %v to UUID", value) } *dst = UUID{UUID: uuid.UUID(pgUUID.Bytes), Status: pgUUID.Status} @@ -92,13 +92,13 @@ func (src *UUID) AssignTo(dst interface{}) error { if nextDst, retry := pgtype.GetAssignToDstType(v); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case pgtype.Null: return pgtype.NullAssignTo(dst) } - return errors.Errorf("cannot assign %v into %T", src, dst) + return fmt.Errorf("cannot assign %v into %T", src, dst) } func (dst *UUID) DecodeText(ci *pgtype.ConnInfo, src []byte) error { @@ -123,7 +123,7 @@ func (dst *UUID) DecodeBinary(ci *pgtype.ConnInfo, src []byte) error { } if len(src) != 16 { - return errors.Errorf("invalid length for UUID: %v", len(src)) + return fmt.Errorf("invalid length for UUID: %v", len(src)) } *dst = UUID{Status: pgtype.Present} @@ -167,7 +167,7 @@ func (dst *UUID) Scan(src interface{}) error { return dst.DecodeText(nil, src) } - return errors.Errorf("cannot scan %T", src) + return fmt.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 148589a4..e8694111 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" - errors "golang.org/x/xerrors" - "github.com/jackc/pgtype" "github.com/shopspring/decimal" ) @@ -78,17 +78,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 errors.Errorf("cannot convert %v to Numeric", value) + return fmt.Errorf("cannot convert %v to Numeric", value) } buf, err := num.EncodeText(nil, nil) if err != nil { - return errors.Errorf("cannot convert %v to Numeric", value) + return fmt.Errorf("cannot convert %v to Numeric", value) } dec, err := decimal.NewFromString(string(buf)) if err != nil { - return errors.Errorf("cannot convert %v to Numeric", value) + return fmt.Errorf("cannot convert %v to Numeric", value) } *dst = Numeric{Decimal: dec, Status: pgtype.Present} } @@ -121,99 +121,99 @@ func (src *Numeric) AssignTo(dst interface{}) error { *v = f case *int: if src.Decimal.Exponent() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, strconv.IntSize) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = int(n) case *int8: if src.Decimal.Exponent() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 8) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = int8(n) case *int16: if src.Decimal.Exponent() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 16) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = int16(n) case *int32: if src.Decimal.Exponent() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 32) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = int32(n) case *int64: if src.Decimal.Exponent() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseInt(src.Decimal.String(), 10, 64) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = int64(n) case *uint: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, strconv.IntSize) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = uint(n) case *uint8: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 8) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = uint8(n) case *uint16: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 16) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = uint16(n) case *uint32: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 32) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = uint32(n) case *uint64: if src.Decimal.Exponent() < 0 || src.Decimal.Sign() < 0 { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } n, err := strconv.ParseUint(src.Decimal.String(), 10, 64) if err != nil { - return errors.Errorf("cannot convert %v to %T", dst, *v) + return fmt.Errorf("cannot convert %v to %T", dst, *v) } *v = uint64(n) default: if nextDst, retry := pgtype.GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case pgtype.Null: return pgtype.NullAssignTo(dst) @@ -300,7 +300,7 @@ func (dst *Numeric) Scan(src interface{}) error { return dst.DecodeText(nil, src) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/float4.go b/float4.go index 5faad54d..89b9e8fa 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/pgio" - errors "golang.org/x/xerrors" ) type Float4 struct { @@ -46,42 +46,42 @@ func (dst *Float4) Set(src interface{}) error { if int32(f32) == value { *dst = Float4{Float: f32, Status: Present} } else { - return errors.Errorf("%v cannot be exactly represented as float32", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float32", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float32", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float32", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float32", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float32", value) + return fmt.Errorf("%v cannot be exactly represented as float32", value) } case string: num, err := strconv.ParseFloat(value, 32) @@ -171,7 +171,7 @@ func (dst *Float4) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Float8", value) + return fmt.Errorf("cannot convert %v to Float8", value) } return nil @@ -214,7 +214,7 @@ func (dst *Float4) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 4 { - return errors.Errorf("invalid length for float4: %v", len(src)) + return fmt.Errorf("invalid length for float4: %v", len(src)) } n := int32(binary.BigEndian.Uint32(src)) @@ -266,7 +266,7 @@ func (dst *Float4) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/float4_array.go b/float4_array.go index 91b3b0e2..41f2ec8f 100644 --- a/float4_array.go +++ b/float4_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Float4Array struct { @@ -96,7 +96,7 @@ func (dst *Float4Array) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for Float4Array", src) + return fmt.Errorf("cannot find dimensions of %v for Float4Array", src) } if elementsLength == 0 { *dst = Float4Array{Status: Present} @@ -106,7 +106,7 @@ func (dst *Float4Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Float4Array", src) + return fmt.Errorf("cannot convert %v to Float4Array", src) } *dst = Float4Array{ @@ -137,7 +137,7 @@ func (dst *Float4Array) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to Float4Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to Float4Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -155,7 +155,7 @@ func (dst *Float4Array) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -168,10 +168,10 @@ func (dst *Float4Array) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to Float4Array") + return 0, fmt.Errorf("cannot convert all values to Float4Array") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in Float4Array", err) + return 0, fmt.Errorf("%v in Float4Array", err) } index++ @@ -233,7 +233,7 @@ func (src *Float4Array) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -248,7 +248,7 @@ func (src *Float4Array) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -256,7 +256,7 @@ func (src *Float4Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *Float4Array) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -272,7 +272,7 @@ func (src *Float4Array) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -290,14 +290,14 @@ func (src *Float4Array) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from Float4Array") + return 0, fmt.Errorf("cannot assign all values from Float4Array") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from Float4Array") + return 0, fmt.Errorf("cannot assign all values from Float4Array") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -456,7 +456,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, errors.Errorf("unable to find oid for type name %v", "float4") + return nil, fmt.Errorf("unable to find oid for type name %v", "float4") } for i := range src.Elements { @@ -500,7 +500,7 @@ func (dst *Float4Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/float8.go b/float8.go index d7412301..4d9e7116 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/pgio" - errors "golang.org/x/xerrors" ) type Float8 struct { @@ -50,28 +50,28 @@ func (dst *Float8) Set(src interface{}) error { if int64(f64) == value { *dst = Float8{Float: f64, Status: Present} } else { - return errors.Errorf("%v cannot be exactly represented as float64", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float64", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float64", value) + return fmt.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 errors.Errorf("%v cannot be exactly represented as float64", value) + return fmt.Errorf("%v cannot be exactly represented as float64", value) } case string: num, err := strconv.ParseFloat(value, 64) @@ -161,7 +161,7 @@ func (dst *Float8) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Float8", value) + return fmt.Errorf("cannot convert %v to Float8", value) } return nil @@ -204,7 +204,7 @@ func (dst *Float8) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return errors.Errorf("invalid length for float4: %v", len(src)) + return fmt.Errorf("invalid length for float4: %v", len(src)) } n := int64(binary.BigEndian.Uint64(src)) @@ -256,7 +256,7 @@ func (dst *Float8) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/float8_array.go b/float8_array.go index 559ee292..836ee19d 100644 --- a/float8_array.go +++ b/float8_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Float8Array struct { @@ -96,7 +96,7 @@ func (dst *Float8Array) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for Float8Array", src) + return fmt.Errorf("cannot find dimensions of %v for Float8Array", src) } if elementsLength == 0 { *dst = Float8Array{Status: Present} @@ -106,7 +106,7 @@ func (dst *Float8Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Float8Array", src) + return fmt.Errorf("cannot convert %v to Float8Array", src) } *dst = Float8Array{ @@ -137,7 +137,7 @@ func (dst *Float8Array) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to Float8Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to Float8Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -155,7 +155,7 @@ func (dst *Float8Array) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -168,10 +168,10 @@ func (dst *Float8Array) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to Float8Array") + return 0, fmt.Errorf("cannot convert all values to Float8Array") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in Float8Array", err) + return 0, fmt.Errorf("%v in Float8Array", err) } index++ @@ -233,7 +233,7 @@ func (src *Float8Array) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -248,7 +248,7 @@ func (src *Float8Array) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -256,7 +256,7 @@ func (src *Float8Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *Float8Array) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -272,7 +272,7 @@ func (src *Float8Array) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -290,14 +290,14 @@ func (src *Float8Array) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from Float8Array") + return 0, fmt.Errorf("cannot assign all values from Float8Array") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from Float8Array") + return 0, fmt.Errorf("cannot assign all values from Float8Array") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -456,7 +456,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, errors.Errorf("unable to find oid for type name %v", "float8") + return nil, fmt.Errorf("unable to find oid for type name %v", "float8") } for i := range src.Elements { @@ -500,7 +500,7 @@ func (dst *Float8Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/go.mod b/go.mod index 990e79f3..f213388a 100644 --- a/go.mod +++ b/go.mod @@ -10,5 +10,4 @@ require ( github.com/lib/pq v1.3.0 github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc github.com/stretchr/testify v1.5.1 - golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 ) diff --git a/hstore.go b/hstore.go index ec510df7..18b413c6 100644 --- a/hstore.go +++ b/hstore.go @@ -4,12 +4,12 @@ import ( "bytes" "database/sql/driver" "encoding/binary" + "errors" + "fmt" "strings" "unicode" "unicode/utf8" - errors "golang.org/x/xerrors" - "github.com/jackc/pgio" ) @@ -41,7 +41,7 @@ func (dst *Hstore) Set(src interface{}) error { } *dst = Hstore{Map: m, Status: Present} default: - return errors.Errorf("cannot convert %v to Hstore", src) + return fmt.Errorf("cannot convert %v to Hstore", src) } return nil @@ -66,7 +66,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 errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } (*v)[k] = val.String } @@ -75,13 +75,13 @@ func (src *Hstore) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *Hstore) DecodeText(ci *ConnInfo, src []byte) error { @@ -113,7 +113,7 @@ func (dst *Hstore) DecodeBinary(ci *ConnInfo, src []byte) error { rp := 0 if len(src[rp:]) < 4 { - return errors.Errorf("hstore incomplete %v", src) + return fmt.Errorf("hstore incomplete %v", src) } pairCount := int(int32(binary.BigEndian.Uint32(src[rp:]))) rp += 4 @@ -122,19 +122,19 @@ func (dst *Hstore) DecodeBinary(ci *ConnInfo, src []byte) error { for i := 0; i < pairCount; i++ { if len(src[rp:]) < 4 { - return errors.Errorf("hstore incomplete %v", src) + return fmt.Errorf("hstore incomplete %v", src) } keyLen := int(int32(binary.BigEndian.Uint32(src[rp:]))) rp += 4 if len(src[rp:]) < keyLen { - return errors.Errorf("hstore incomplete %v", src) + return fmt.Errorf("hstore incomplete %v", src) } key := string(src[rp : rp+keyLen]) rp += keyLen if len(src[rp:]) < 4 { - return errors.Errorf("hstore incomplete %v", src) + return fmt.Errorf("hstore incomplete %v", src) } valueLen := int(int32(binary.BigEndian.Uint32(src[rp:]))) rp += 4 @@ -338,13 +338,13 @@ func parseHstore(s string) (k []string, v []Text, err error) { case r == 'N': state = hsNul default: - err = errors.Errorf("Invalid character '%c' after '=>', expecting '\"' or 'NULL'", r) + err = fmt.Errorf("Invalid character '%c' after '=>', expecting '\"' or 'NULL'", r) } default: - err = errors.Errorf("Invalid character after '=', expecting '>'") + err = fmt.Errorf("Invalid character after '=', expecting '>'") } } else { - err = errors.Errorf("Invalid character '%c' after value, expecting '='", r) + err = fmt.Errorf("Invalid character '%c' after value, expecting '='", r) } case hsVal: switch r { @@ -381,7 +381,7 @@ func parseHstore(s string) (k []string, v []Text, err error) { values = append(values, Text{Status: Null}) state = hsNext } else { - err = errors.Errorf("Invalid NULL value: 'N%s'", string(nulBuf)) + err = fmt.Errorf("Invalid NULL value: 'N%s'", string(nulBuf)) } case hsNext: if r == ',' { @@ -393,10 +393,10 @@ func parseHstore(s string) (k []string, v []Text, err error) { r, end = p.Consume() state = hsKey default: - err = errors.Errorf("Invalid character '%c' after ', ', expecting \"", r) + err = fmt.Errorf("Invalid character '%c' after ', ', expecting \"", r) } } else { - err = errors.Errorf("Invalid character '%c' after value, expecting ','", r) + err = fmt.Errorf("Invalid character '%c' after value, expecting ','", r) } } @@ -430,7 +430,7 @@ func (dst *Hstore) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/hstore_array.go b/hstore_array.go index a44ea629..47b4b3ff 100644 --- a/hstore_array.go +++ b/hstore_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type HstoreArray struct { @@ -77,7 +77,7 @@ func (dst *HstoreArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for HstoreArray", src) + return fmt.Errorf("cannot find dimensions of %v for HstoreArray", src) } if elementsLength == 0 { *dst = HstoreArray{Status: Present} @@ -87,7 +87,7 @@ func (dst *HstoreArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to HstoreArray", src) + return fmt.Errorf("cannot convert %v to HstoreArray", src) } *dst = HstoreArray{ @@ -118,7 +118,7 @@ func (dst *HstoreArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to HstoreArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to HstoreArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -136,7 +136,7 @@ func (dst *HstoreArray) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -149,10 +149,10 @@ func (dst *HstoreArray) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to HstoreArray") + return 0, fmt.Errorf("cannot convert all values to HstoreArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in HstoreArray", err) + return 0, fmt.Errorf("%v in HstoreArray", err) } index++ @@ -205,7 +205,7 @@ func (src *HstoreArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -220,7 +220,7 @@ func (src *HstoreArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -228,7 +228,7 @@ func (src *HstoreArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *HstoreArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -244,7 +244,7 @@ func (src *HstoreArray) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -262,14 +262,14 @@ func (src *HstoreArray) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from HstoreArray") + return 0, fmt.Errorf("cannot assign all values from HstoreArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from HstoreArray") + return 0, fmt.Errorf("cannot assign all values from HstoreArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -428,7 +428,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, errors.Errorf("unable to find oid for type name %v", "hstore") + return nil, fmt.Errorf("unable to find oid for type name %v", "hstore") } for i := range src.Elements { @@ -472,7 +472,7 @@ func (dst *HstoreArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/inet.go b/inet.go index b4498191..101b9ab4 100644 --- a/inet.go +++ b/inet.go @@ -2,9 +2,8 @@ package pgtype import ( "database/sql/driver" + "fmt" "net" - - errors "golang.org/x/xerrors" ) // Network address family is dependent on server socket.h value for AF_INET. @@ -73,7 +72,7 @@ func (dst *Inet) Set(src interface{}) error { if originalSrc, ok := underlyingPtrType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Inet", value) + return fmt.Errorf("cannot convert %v to Inet", value) } return nil @@ -104,7 +103,7 @@ func (src *Inet) AssignTo(dst interface{}) error { return nil case *net.IP: if oneCount, bitCount := src.IPNet.Mask.Size(); oneCount != bitCount { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } *v = make(net.IP, len(src.IPNet.IP)) copy(*v, src.IPNet.IP) @@ -113,13 +112,13 @@ func (src *Inet) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *Inet) DecodeText(ci *ConnInfo, src []byte) error { @@ -157,7 +156,7 @@ func (dst *Inet) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 && len(src) != 20 { - return errors.Errorf("Received an invalid size for a inet: %d", len(src)) + return fmt.Errorf("Received an invalid size for a inet: %d", len(src)) } // ignore family @@ -202,7 +201,7 @@ func (src Inet) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case net.IPv6len: family = defaultAFInet6 default: - return nil, errors.Errorf("Unexpected IP length: %v", len(src.IPNet.IP)) + return nil, fmt.Errorf("Unexpected IP length: %v", len(src.IPNet.IP)) } buf = append(buf, family) @@ -234,7 +233,7 @@ func (dst *Inet) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/inet_array.go b/inet_array.go index 30adeabb..2460a1c4 100644 --- a/inet_array.go +++ b/inet_array.go @@ -5,11 +5,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "net" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type InetArray struct { @@ -116,7 +116,7 @@ func (dst *InetArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for InetArray", src) + return fmt.Errorf("cannot find dimensions of %v for InetArray", src) } if elementsLength == 0 { *dst = InetArray{Status: Present} @@ -126,7 +126,7 @@ func (dst *InetArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to InetArray", src) + return fmt.Errorf("cannot convert %v to InetArray", src) } *dst = InetArray{ @@ -157,7 +157,7 @@ func (dst *InetArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to InetArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to InetArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -175,7 +175,7 @@ func (dst *InetArray) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -188,10 +188,10 @@ func (dst *InetArray) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to InetArray") + return 0, fmt.Errorf("cannot convert all values to InetArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in InetArray", err) + return 0, fmt.Errorf("%v in InetArray", err) } index++ @@ -262,7 +262,7 @@ func (src *InetArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -277,7 +277,7 @@ func (src *InetArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -285,7 +285,7 @@ func (src *InetArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *InetArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -301,7 +301,7 @@ func (src *InetArray) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -319,14 +319,14 @@ func (src *InetArray) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from InetArray") + return 0, fmt.Errorf("cannot assign all values from InetArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from InetArray") + return 0, fmt.Errorf("cannot assign all values from InetArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -485,7 +485,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, errors.Errorf("unable to find oid for type name %v", "inet") + return nil, fmt.Errorf("unable to find oid for type name %v", "inet") } for i := range src.Elements { @@ -529,7 +529,7 @@ func (dst *InetArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int2.go b/int2.go index b7517881..3eb5aeb5 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/pgio" - errors "golang.org/x/xerrors" ) type Int2 struct { @@ -37,46 +37,46 @@ func (dst *Int2) Set(src interface{}) error { *dst = Int2{Int: int16(value), Status: Present} case uint16: if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case int32: if value < math.MinInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case uint32: if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case int64: if value < math.MinInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case uint64: if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case int: if value < math.MinInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case uint: if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%d is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case string: @@ -87,12 +87,12 @@ func (dst *Int2) Set(src interface{}) error { *dst = Int2{Int: int16(num), Status: Present} case float32: if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%f is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case float64: if value > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", value) + return fmt.Errorf("%f is greater than maximum value for Int2", value) } *dst = Int2{Int: int16(value), Status: Present} case *int8: @@ -177,7 +177,7 @@ func (dst *Int2) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int2", value) + return fmt.Errorf("cannot convert %v to Int2", value) } return nil @@ -220,7 +220,7 @@ func (dst *Int2) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 2 { - return errors.Errorf("invalid length for int2: %v", len(src)) + return fmt.Errorf("invalid length for int2: %v", len(src)) } n := int16(binary.BigEndian.Uint16(src)) @@ -260,10 +260,10 @@ func (dst *Int2) Scan(src interface{}) error { switch src := src.(type) { case int64: if src < math.MinInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", src) + return fmt.Errorf("%d is greater than maximum value for Int2", src) } if src > math.MaxInt16 { - return errors.Errorf("%d is greater than maximum value for Int2", src) + return fmt.Errorf("%d is greater than maximum value for Int2", src) } *dst = Int2{Int: int16(src), Status: Present} return nil @@ -275,7 +275,7 @@ func (dst *Int2) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int2_array.go b/int2_array.go index f4bd64cc..a5133845 100644 --- a/int2_array.go +++ b/int2_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Int2Array struct { @@ -362,7 +362,7 @@ func (dst *Int2Array) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for Int2Array", src) + return fmt.Errorf("cannot find dimensions of %v for Int2Array", src) } if elementsLength == 0 { *dst = Int2Array{Status: Present} @@ -372,7 +372,7 @@ func (dst *Int2Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int2Array", src) + return fmt.Errorf("cannot convert %v to Int2Array", src) } *dst = Int2Array{ @@ -403,7 +403,7 @@ func (dst *Int2Array) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to Int2Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to Int2Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -421,7 +421,7 @@ func (dst *Int2Array) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -434,10 +434,10 @@ func (dst *Int2Array) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to Int2Array") + return 0, fmt.Errorf("cannot convert all values to Int2Array") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in Int2Array", err) + return 0, fmt.Errorf("%v in Int2Array", err) } index++ @@ -625,7 +625,7 @@ func (src *Int2Array) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -640,7 +640,7 @@ func (src *Int2Array) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -648,7 +648,7 @@ func (src *Int2Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *Int2Array) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -664,7 +664,7 @@ func (src *Int2Array) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -682,14 +682,14 @@ func (src *Int2Array) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from Int2Array") + return 0, fmt.Errorf("cannot assign all values from Int2Array") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from Int2Array") + return 0, fmt.Errorf("cannot assign all values from Int2Array") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -848,7 +848,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, errors.Errorf("unable to find oid for type name %v", "int2") + return nil, fmt.Errorf("unable to find oid for type name %v", "int2") } for i := range src.Elements { @@ -892,7 +892,7 @@ func (dst *Int2Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int4.go b/int4.go index 66652bbe..22b48e5e 100644 --- a/int4.go +++ b/int4.go @@ -4,11 +4,11 @@ import ( "database/sql/driver" "encoding/binary" "encoding/json" + "fmt" "math" "strconv" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Int4 struct { @@ -42,33 +42,33 @@ func (dst *Int4) Set(src interface{}) error { *dst = Int4{Int: int32(value), Status: Present} case uint32: if value > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case int64: if value < math.MinInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%d is greater than maximum value for Int4", value) } if value > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case uint64: if value > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case int: if value < math.MinInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%d is greater than maximum value for Int4", value) } if value > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case uint: if value > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%d is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case string: @@ -79,12 +79,12 @@ func (dst *Int4) Set(src interface{}) error { *dst = Int4{Int: int32(num), Status: Present} case float32: if value > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%f is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case float64: if value > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", value) + return fmt.Errorf("%f is greater than maximum value for Int4", value) } *dst = Int4{Int: int32(value), Status: Present} case *int8: @@ -169,7 +169,7 @@ func (dst *Int4) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int4", value) + return fmt.Errorf("cannot convert %v to Int4", value) } return nil @@ -212,7 +212,7 @@ func (dst *Int4) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 4 { - return errors.Errorf("invalid length for int4: %v", len(src)) + return fmt.Errorf("invalid length for int4: %v", len(src)) } n := int32(binary.BigEndian.Uint32(src)) @@ -252,10 +252,10 @@ func (dst *Int4) Scan(src interface{}) error { switch src := src.(type) { case int64: if src < math.MinInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", src) + return fmt.Errorf("%d is greater than maximum value for Int4", src) } if src > math.MaxInt32 { - return errors.Errorf("%d is greater than maximum value for Int4", src) + return fmt.Errorf("%d is greater than maximum value for Int4", src) } *dst = Int4{Int: int32(src), Status: Present} return nil @@ -267,7 +267,7 @@ func (dst *Int4) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int4_array.go b/int4_array.go index 528310ff..de26236f 100644 --- a/int4_array.go +++ b/int4_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Int4Array struct { @@ -362,7 +362,7 @@ func (dst *Int4Array) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for Int4Array", src) + return fmt.Errorf("cannot find dimensions of %v for Int4Array", src) } if elementsLength == 0 { *dst = Int4Array{Status: Present} @@ -372,7 +372,7 @@ func (dst *Int4Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int4Array", src) + return fmt.Errorf("cannot convert %v to Int4Array", src) } *dst = Int4Array{ @@ -403,7 +403,7 @@ func (dst *Int4Array) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to Int4Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to Int4Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -421,7 +421,7 @@ func (dst *Int4Array) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -434,10 +434,10 @@ func (dst *Int4Array) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to Int4Array") + return 0, fmt.Errorf("cannot convert all values to Int4Array") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in Int4Array", err) + return 0, fmt.Errorf("%v in Int4Array", err) } index++ @@ -625,7 +625,7 @@ func (src *Int4Array) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -640,7 +640,7 @@ func (src *Int4Array) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -648,7 +648,7 @@ func (src *Int4Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *Int4Array) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -664,7 +664,7 @@ func (src *Int4Array) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -682,14 +682,14 @@ func (src *Int4Array) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from Int4Array") + return 0, fmt.Errorf("cannot assign all values from Int4Array") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from Int4Array") + return 0, fmt.Errorf("cannot assign all values from Int4Array") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -848,7 +848,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, errors.Errorf("unable to find oid for type name %v", "int4") + return nil, fmt.Errorf("unable to find oid for type name %v", "int4") } for i := range src.Elements { @@ -892,7 +892,7 @@ func (dst *Int4Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int4range.go b/int4range.go index 442f2501..c7f51fa6 100644 --- a/int4range.go +++ b/int4range.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" + "fmt" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Int4range struct { @@ -30,7 +30,7 @@ func (dst *Int4range) Set(src interface{}) error { case string: return dst.DecodeText(nil, []byte(value)) default: - return errors.Errorf("cannot convert %v to Int4range", src) + return fmt.Errorf("cannot convert %v to Int4range", src) } return nil @@ -48,7 +48,7 @@ func (dst Int4range) Get() interface{} { } func (src *Int4range) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Int4range) DecodeText(ci *ConnInfo, src []byte) error { @@ -137,7 +137,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) + return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -147,7 +147,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -158,7 +158,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -168,7 +168,7 @@ func (src Int4range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) + return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -192,7 +192,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) + return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -202,7 +202,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) + return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -218,7 +218,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -233,7 +233,7 @@ func (src Int4range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -258,7 +258,7 @@ func (dst *Int4range) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int8.go b/int8.go index f0114194..0e089979 100644 --- a/int8.go +++ b/int8.go @@ -4,11 +4,11 @@ import ( "database/sql/driver" "encoding/binary" "encoding/json" + "fmt" "math" "strconv" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Int8 struct { @@ -46,20 +46,20 @@ func (dst *Int8) Set(src interface{}) error { *dst = Int8{Int: int64(value), Status: Present} case uint64: if value > math.MaxInt64 { - return errors.Errorf("%d is greater than maximum value for Int8", value) + return fmt.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 errors.Errorf("%d is greater than maximum value for Int8", value) + return fmt.Errorf("%d is greater than maximum value for Int8", value) } if int64(value) > math.MaxInt64 { - return errors.Errorf("%d is greater than maximum value for Int8", value) + return fmt.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 errors.Errorf("%d is greater than maximum value for Int8", value) + return fmt.Errorf("%d is greater than maximum value for Int8", value) } *dst = Int8{Int: int64(value), Status: Present} case string: @@ -70,12 +70,12 @@ func (dst *Int8) Set(src interface{}) error { *dst = Int8{Int: num, Status: Present} case float32: if value > math.MaxInt64 { - return errors.Errorf("%d is greater than maximum value for Int8", value) + return fmt.Errorf("%f is greater than maximum value for Int8", value) } *dst = Int8{Int: int64(value), Status: Present} case float64: if value > math.MaxInt64 { - return errors.Errorf("%d is greater than maximum value for Int8", value) + return fmt.Errorf("%f is greater than maximum value for Int8", value) } *dst = Int8{Int: int64(value), Status: Present} case *int8: @@ -160,7 +160,7 @@ func (dst *Int8) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int8", value) + return fmt.Errorf("cannot convert %v to Int8", value) } return nil @@ -203,7 +203,7 @@ func (dst *Int8) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return errors.Errorf("invalid length for int8: %v", len(src)) + return fmt.Errorf("invalid length for int8: %v", len(src)) } n := int64(binary.BigEndian.Uint64(src)) @@ -253,7 +253,7 @@ func (dst *Int8) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int8_array.go b/int8_array.go index b1e52a97..e405b326 100644 --- a/int8_array.go +++ b/int8_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Int8Array struct { @@ -362,7 +362,7 @@ func (dst *Int8Array) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for Int8Array", src) + return fmt.Errorf("cannot find dimensions of %v for Int8Array", src) } if elementsLength == 0 { *dst = Int8Array{Status: Present} @@ -372,7 +372,7 @@ func (dst *Int8Array) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Int8Array", src) + return fmt.Errorf("cannot convert %v to Int8Array", src) } *dst = Int8Array{ @@ -403,7 +403,7 @@ func (dst *Int8Array) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to Int8Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to Int8Array, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -421,7 +421,7 @@ func (dst *Int8Array) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -434,10 +434,10 @@ func (dst *Int8Array) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to Int8Array") + return 0, fmt.Errorf("cannot convert all values to Int8Array") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in Int8Array", err) + return 0, fmt.Errorf("%v in Int8Array", err) } index++ @@ -625,7 +625,7 @@ func (src *Int8Array) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -640,7 +640,7 @@ func (src *Int8Array) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -648,7 +648,7 @@ func (src *Int8Array) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *Int8Array) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -664,7 +664,7 @@ func (src *Int8Array) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -682,14 +682,14 @@ func (src *Int8Array) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from Int8Array") + return 0, fmt.Errorf("cannot assign all values from Int8Array") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from Int8Array") + return 0, fmt.Errorf("cannot assign all values from Int8Array") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -848,7 +848,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, errors.Errorf("unable to find oid for type name %v", "int8") + return nil, fmt.Errorf("unable to find oid for type name %v", "int8") } for i := range src.Elements { @@ -892,7 +892,7 @@ func (dst *Int8Array) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/int8range.go b/int8range.go index 92fcb136..71369373 100644 --- a/int8range.go +++ b/int8range.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" + "fmt" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Int8range struct { @@ -30,7 +30,7 @@ func (dst *Int8range) Set(src interface{}) error { case string: return dst.DecodeText(nil, []byte(value)) default: - return errors.Errorf("cannot convert %v to Int8range", src) + return fmt.Errorf("cannot convert %v to Int8range", src) } return nil @@ -48,7 +48,7 @@ func (dst Int8range) Get() interface{} { } func (src *Int8range) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Int8range) DecodeText(ci *ConnInfo, src []byte) error { @@ -137,7 +137,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) + return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -147,7 +147,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -158,7 +158,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -168,7 +168,7 @@ func (src Int8range) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) + return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -192,7 +192,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) + return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -202,7 +202,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) + return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -218,7 +218,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -233,7 +233,7 @@ func (src Int8range) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -258,7 +258,7 @@ func (dst *Int8range) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/interval.go b/interval.go index 309e880c..b01fbb7c 100644 --- a/interval.go +++ b/interval.go @@ -9,7 +9,6 @@ import ( "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) const ( @@ -47,7 +46,7 @@ func (dst *Interval) Set(src interface{}) error { if originalSrc, ok := underlyingPtrType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Interval", value) + return fmt.Errorf("cannot convert %v to Interval", value) } return nil @@ -76,13 +75,13 @@ func (src *Interval) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *Interval) DecodeText(ci *ConnInfo, src []byte) error { @@ -100,7 +99,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 errors.Errorf("bad interval format") + return fmt.Errorf("bad interval format") } switch parts[i+1] { @@ -116,7 +115,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 errors.Errorf("bad interval format") + return fmt.Errorf("bad interval format") } var negative bool @@ -127,26 +126,26 @@ func (dst *Interval) DecodeText(ci *ConnInfo, src []byte) error { hours, err := strconv.ParseInt(timeParts[0], 10, 64) if err != nil { - return errors.Errorf("bad interval hour format: %s", timeParts[0]) + return fmt.Errorf("bad interval hour format: %s", timeParts[0]) } minutes, err := strconv.ParseInt(timeParts[1], 10, 64) if err != nil { - return errors.Errorf("bad interval minute format: %s", timeParts[1]) + return fmt.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 errors.Errorf("bad interval second format: %s", secondParts[0]) + return fmt.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 errors.Errorf("bad interval decimal format: %s", secondParts[1]) + return fmt.Errorf("bad interval decimal format: %s", secondParts[1]) } for i := 0; i < 6-len(secondParts[1]); i++ { @@ -175,7 +174,7 @@ func (dst *Interval) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 16 { - return errors.Errorf("Received an invalid size for a interval: %d", len(src)) + return fmt.Errorf("Received an invalid size for a interval: %d", len(src)) } microseconds := int64(binary.BigEndian.Uint64(src)) @@ -249,7 +248,7 @@ func (dst *Interval) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/json.go b/json.go index 922da50d..32bef5e7 100644 --- a/json.go +++ b/json.go @@ -3,8 +3,8 @@ package pgtype import ( "database/sql/driver" "encoding/json" - - errors "golang.org/x/xerrors" + "errors" + "fmt" ) type JSON struct { @@ -82,7 +82,7 @@ func (src *JSON) AssignTo(dst interface{}) error { if src.Status == Present { *v = string(src.Bytes) } else { - return errors.Errorf("cannot assign non-present status to %T", dst) + return fmt.Errorf("cannot assign non-present status to %T", dst) } case **string: if src.Status == Present { @@ -166,7 +166,7 @@ func (dst *JSON) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/jsonb.go b/jsonb.go index c129ac9b..c9dafc93 100644 --- a/jsonb.go +++ b/jsonb.go @@ -2,8 +2,7 @@ package pgtype import ( "database/sql/driver" - - errors "golang.org/x/xerrors" + "fmt" ) type JSONB JSON @@ -35,11 +34,11 @@ func (dst *JSONB) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) == 0 { - return errors.Errorf("jsonb too short") + return fmt.Errorf("jsonb too short") } if src[0] != 1 { - return errors.Errorf("unknown jsonb version number %d", src[0]) + return fmt.Errorf("unknown jsonb version number %d", src[0]) } *dst = JSONB{Bytes: src[1:], Status: Present} diff --git a/jsonb_array.go b/jsonb_array.go index 5d658ed5..c4b7cd3d 100644 --- a/jsonb_array.go +++ b/jsonb_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type JSONBArray struct { @@ -96,7 +96,7 @@ func (dst *JSONBArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for JSONBArray", src) + return fmt.Errorf("cannot find dimensions of %v for JSONBArray", src) } if elementsLength == 0 { *dst = JSONBArray{Status: Present} @@ -106,7 +106,7 @@ func (dst *JSONBArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to JSONBArray", src) + return fmt.Errorf("cannot convert %v to JSONBArray", src) } *dst = JSONBArray{ @@ -137,7 +137,7 @@ func (dst *JSONBArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to JSONBArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to JSONBArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -155,7 +155,7 @@ func (dst *JSONBArray) setRecursive(value reflect.Value, index, dimension int) ( valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -168,10 +168,10 @@ func (dst *JSONBArray) setRecursive(value reflect.Value, index, dimension int) ( return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to JSONBArray") + return 0, fmt.Errorf("cannot convert all values to JSONBArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in JSONBArray", err) + return 0, fmt.Errorf("%v in JSONBArray", err) } index++ @@ -233,7 +233,7 @@ func (src *JSONBArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -248,7 +248,7 @@ func (src *JSONBArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -256,7 +256,7 @@ func (src *JSONBArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *JSONBArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -272,7 +272,7 @@ func (src *JSONBArray) assignToRecursive(value reflect.Value, index, dimension i if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -290,14 +290,14 @@ func (src *JSONBArray) assignToRecursive(value reflect.Value, index, dimension i return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from JSONBArray") + return 0, fmt.Errorf("cannot assign all values from JSONBArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from JSONBArray") + return 0, fmt.Errorf("cannot assign all values from JSONBArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -456,7 +456,7 @@ func (src JSONBArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("jsonb"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "jsonb") + return nil, fmt.Errorf("unable to find oid for type name %v", "jsonb") } for i := range src.Elements { @@ -500,7 +500,7 @@ func (dst *JSONBArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/line.go b/line.go index 737f5d86..3564b174 100644 --- a/line.go +++ b/line.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Line struct { @@ -18,7 +17,7 @@ type Line struct { } func (dst *Line) Set(src interface{}) error { - return errors.Errorf("cannot convert %v to Line", src) + return fmt.Errorf("cannot convert %v to Line", src) } func (dst Line) Get() interface{} { @@ -33,7 +32,7 @@ func (dst Line) Get() interface{} { } func (src *Line) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Line) DecodeText(ci *ConnInfo, src []byte) error { @@ -43,12 +42,12 @@ func (dst *Line) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 7 { - return errors.Errorf("invalid length for Line: %v", len(src)) + return fmt.Errorf("invalid length for Line: %v", len(src)) } parts := strings.SplitN(string(src[1:len(src)-1]), ",", 3) if len(parts) < 3 { - return errors.Errorf("invalid format for line") + return fmt.Errorf("invalid format for line") } a, err := strconv.ParseFloat(parts[0], 64) @@ -77,7 +76,7 @@ func (dst *Line) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 24 { - return errors.Errorf("invalid length for Line: %v", len(src)) + return fmt.Errorf("invalid length for Line: %v", len(src)) } a := binary.BigEndian.Uint64(src) @@ -140,7 +139,7 @@ func (dst *Line) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/lseg.go b/lseg.go index a16dcea3..5c4babb6 100644 --- a/lseg.go +++ b/lseg.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Lseg struct { @@ -18,7 +17,7 @@ type Lseg struct { } func (dst *Lseg) Set(src interface{}) error { - return errors.Errorf("cannot convert %v to Lseg", src) + return fmt.Errorf("cannot convert %v to Lseg", src) } func (dst Lseg) Get() interface{} { @@ -33,7 +32,7 @@ func (dst Lseg) Get() interface{} { } func (src *Lseg) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Lseg) DecodeText(ci *ConnInfo, src []byte) error { @@ -43,7 +42,7 @@ func (dst *Lseg) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 11 { - return errors.Errorf("invalid length for Lseg: %v", len(src)) + return fmt.Errorf("invalid length for Lseg: %v", len(src)) } str := string(src[2:]) @@ -90,7 +89,7 @@ func (dst *Lseg) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 32 { - return errors.Errorf("invalid length for Lseg: %v", len(src)) + return fmt.Errorf("invalid length for Lseg: %v", len(src)) } x1 := binary.BigEndian.Uint64(src) @@ -157,7 +156,7 @@ func (dst *Lseg) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/macaddr.go b/macaddr.go index 6cc14114..1d3cfe7b 100644 --- a/macaddr.go +++ b/macaddr.go @@ -2,9 +2,8 @@ package pgtype import ( "database/sql/driver" + "fmt" "net" - - errors "golang.org/x/xerrors" ) type Macaddr struct { @@ -52,7 +51,7 @@ func (dst *Macaddr) Set(src interface{}) error { if originalSrc, ok := underlyingPtrType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Macaddr", value) + return fmt.Errorf("cannot convert %v to Macaddr", value) } return nil @@ -84,13 +83,13 @@ func (src *Macaddr) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *Macaddr) DecodeText(ci *ConnInfo, src []byte) error { @@ -115,7 +114,7 @@ func (dst *Macaddr) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 6 { - return errors.Errorf("Received an invalid size for a macaddr: %d", len(src)) + return fmt.Errorf("Received an invalid size for a macaddr: %d", len(src)) } addr := make(net.HardwareAddr, 6) @@ -165,7 +164,7 @@ func (dst *Macaddr) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/macaddr_array.go b/macaddr_array.go index 0ac2618e..bdb1f203 100644 --- a/macaddr_array.go +++ b/macaddr_array.go @@ -5,11 +5,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "net" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type MacaddrArray struct { @@ -97,7 +97,7 @@ func (dst *MacaddrArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for MacaddrArray", src) + return fmt.Errorf("cannot find dimensions of %v for MacaddrArray", src) } if elementsLength == 0 { *dst = MacaddrArray{Status: Present} @@ -107,7 +107,7 @@ func (dst *MacaddrArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to MacaddrArray", src) + return fmt.Errorf("cannot convert %v to MacaddrArray", src) } *dst = MacaddrArray{ @@ -138,7 +138,7 @@ func (dst *MacaddrArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to MacaddrArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to MacaddrArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -156,7 +156,7 @@ func (dst *MacaddrArray) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -169,10 +169,10 @@ func (dst *MacaddrArray) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to MacaddrArray") + return 0, fmt.Errorf("cannot convert all values to MacaddrArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in MacaddrArray", err) + return 0, fmt.Errorf("%v in MacaddrArray", err) } index++ @@ -234,7 +234,7 @@ func (src *MacaddrArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -249,7 +249,7 @@ func (src *MacaddrArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -257,7 +257,7 @@ func (src *MacaddrArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *MacaddrArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -273,7 +273,7 @@ func (src *MacaddrArray) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -291,14 +291,14 @@ func (src *MacaddrArray) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from MacaddrArray") + return 0, fmt.Errorf("cannot assign all values from MacaddrArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from MacaddrArray") + return 0, fmt.Errorf("cannot assign all values from MacaddrArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -457,7 +457,7 @@ func (src MacaddrArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("macaddr"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "macaddr") + return nil, fmt.Errorf("unable to find oid for type name %v", "macaddr") } for i := range src.Elements { @@ -501,7 +501,7 @@ func (dst *MacaddrArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/numeric.go b/numeric.go index 4d966d5e..a7efa704 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/pgio" - errors "golang.org/x/xerrors" ) // PostgreSQL internal numeric storage uses 16-bit "digits" with base of 10,000 @@ -197,7 +197,7 @@ func (dst *Numeric) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Numeric", value) + return fmt.Errorf("cannot convert %v to Numeric", value) } return nil @@ -236,10 +236,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt) > 0 { - return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt) < 0 { - return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int(normalizedInt.Int64()) case *int8: @@ -248,10 +248,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt8) > 0 { - return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt8) < 0 { - return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int8(normalizedInt.Int64()) case *int16: @@ -260,10 +260,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt16) > 0 { - return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt16) < 0 { - return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int16(normalizedInt.Int64()) case *int32: @@ -272,10 +272,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt32) > 0 { - return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt32) < 0 { - return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = int32(normalizedInt.Int64()) case *int64: @@ -284,10 +284,10 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(bigMaxInt64) > 0 { - return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v) } if normalizedInt.Cmp(bigMinInt64) < 0 { - return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v) + return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v) } *v = normalizedInt.Int64() case *uint: @@ -296,9 +296,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) + return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint) > 0 { - return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint(normalizedInt.Uint64()) case *uint8: @@ -307,9 +307,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) + return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint8) > 0 { - return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint8(normalizedInt.Uint64()) case *uint16: @@ -318,9 +318,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) + return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint16) > 0 { - return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint16(normalizedInt.Uint64()) case *uint32: @@ -329,9 +329,9 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) + return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint32) > 0 { - return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = uint32(normalizedInt.Uint64()) case *uint64: @@ -340,16 +340,16 @@ func (src *Numeric) AssignTo(dst interface{}) error { return err } if normalizedInt.Cmp(big0) < 0 { - return errors.Errorf("%d is less than zero for %T", normalizedInt, *v) + return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v) } else if normalizedInt.Cmp(bigMaxUint64) > 0 { - return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) + return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v) } *v = normalizedInt.Uint64() default: if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) @@ -377,7 +377,7 @@ func (dst *Numeric) toBigInt() (*big.Int, error) { remainder := &big.Int{} num.DivMod(num, div, remainder) if remainder.Cmp(big0) != 0 { - return nil, errors.Errorf("cannot convert %v to integer", dst) + return nil, fmt.Errorf("cannot convert %v to integer", dst) } return num, nil } @@ -435,7 +435,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, errors.Errorf("%s is not a number", str) + return nil, 0, fmt.Errorf("%s is not a number", str) } return accum, exp, nil @@ -448,7 +448,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) < 8 { - return errors.Errorf("numeric incomplete %v", src) + return fmt.Errorf("numeric incomplete %v", src) } rp := 0 @@ -472,7 +472,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src[rp:]) < int(ndigits)*2 { - return errors.Errorf("numeric incomplete %v", src) + return fmt.Errorf("numeric incomplete %v", src) } accum := &big.Int{} @@ -493,7 +493,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error { case 4: mul = bigNBaseX4 default: - return errors.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead) + return fmt.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead) } accum.Mul(accum, mul) } @@ -695,7 +695,7 @@ func (dst *Numeric) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/numeric_array.go b/numeric_array.go index 1c2ae489..31899dec 100644 --- a/numeric_array.go +++ b/numeric_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type NumericArray struct { @@ -210,7 +210,7 @@ func (dst *NumericArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for NumericArray", src) + return fmt.Errorf("cannot find dimensions of %v for NumericArray", src) } if elementsLength == 0 { *dst = NumericArray{Status: Present} @@ -220,7 +220,7 @@ func (dst *NumericArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to NumericArray", src) + return fmt.Errorf("cannot convert %v to NumericArray", src) } *dst = NumericArray{ @@ -251,7 +251,7 @@ func (dst *NumericArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to NumericArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to NumericArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -269,7 +269,7 @@ func (dst *NumericArray) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -282,10 +282,10 @@ func (dst *NumericArray) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to NumericArray") + return 0, fmt.Errorf("cannot convert all values to NumericArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in NumericArray", err) + return 0, fmt.Errorf("%v in NumericArray", err) } index++ @@ -401,7 +401,7 @@ func (src *NumericArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -416,7 +416,7 @@ func (src *NumericArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -424,7 +424,7 @@ func (src *NumericArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *NumericArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -440,7 +440,7 @@ func (src *NumericArray) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -458,14 +458,14 @@ func (src *NumericArray) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from NumericArray") + return 0, fmt.Errorf("cannot assign all values from NumericArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from NumericArray") + return 0, fmt.Errorf("cannot assign all values from NumericArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -624,7 +624,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, errors.Errorf("unable to find oid for type name %v", "numeric") + return nil, fmt.Errorf("unable to find oid for type name %v", "numeric") } for i := range src.Elements { @@ -668,7 +668,7 @@ func (dst *NumericArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/numrange.go b/numrange.go index 40467686..3d5951a2 100644 --- a/numrange.go +++ b/numrange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" + "fmt" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Numrange struct { @@ -30,7 +30,7 @@ func (dst *Numrange) Set(src interface{}) error { case string: return dst.DecodeText(nil, []byte(value)) default: - return errors.Errorf("cannot convert %v to Numrange", src) + return fmt.Errorf("cannot convert %v to Numrange", src) } return nil @@ -48,7 +48,7 @@ func (dst Numrange) Get() interface{} { } func (src *Numrange) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Numrange) DecodeText(ci *ConnInfo, src []byte) error { @@ -137,7 +137,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) + return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -147,7 +147,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -158,7 +158,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -168,7 +168,7 @@ func (src Numrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) + return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -192,7 +192,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) + return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -202,7 +202,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) + return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -218,7 +218,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -233,7 +233,7 @@ func (src Numrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -258,7 +258,7 @@ func (dst *Numrange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/oid.go b/oid.go index 593a5261..31677e89 100644 --- a/oid.go +++ b/oid.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "strconv" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) // 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 errors.Errorf("cannot decode nil into OID") + return fmt.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 errors.Errorf("cannot decode nil into OID") + return fmt.Errorf("cannot decode nil into OID") } if len(src) != 4 { - return errors.Errorf("invalid length: %v", len(src)) + return fmt.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 errors.Errorf("cannot scan NULL into %T", src) + return fmt.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 errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/path.go b/path.go index c5031330..9f89969e 100644 --- a/path.go +++ b/path.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Path struct { @@ -19,7 +18,7 @@ type Path struct { } func (dst *Path) Set(src interface{}) error { - return errors.Errorf("cannot convert %v to Path", src) + return fmt.Errorf("cannot convert %v to Path", src) } func (dst Path) Get() interface{} { @@ -34,7 +33,7 @@ func (dst Path) Get() interface{} { } func (src *Path) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Path) DecodeText(ci *ConnInfo, src []byte) error { @@ -44,7 +43,7 @@ func (dst *Path) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 7 { - return errors.Errorf("invalid length for Path: %v", len(src)) + return fmt.Errorf("invalid length for Path: %v", len(src)) } closed := src[0] == '(' @@ -87,7 +86,7 @@ func (dst *Path) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return errors.Errorf("invalid length for Path: %v", len(src)) + return fmt.Errorf("invalid length for Path: %v", len(src)) } closed := src[0] == 1 @@ -96,7 +95,7 @@ func (dst *Path) DecodeBinary(ci *ConnInfo, src []byte) error { rp := 5 if 5+pointCount*16 != len(src) { - return errors.Errorf("invalid length for Path with %d points: %v", pointCount, len(src)) + return fmt.Errorf("invalid length for Path with %d points: %v", pointCount, len(src)) } points := make([]Vec2, pointCount) @@ -187,7 +186,7 @@ func (dst *Path) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/pgtype.go b/pgtype.go index c5e537cd..f1d40146 100644 --- a/pgtype.go +++ b/pgtype.go @@ -3,13 +3,12 @@ package pgtype import ( "database/sql" "encoding/binary" + "errors" "fmt" "math" "net" "reflect" "time" - - errors "golang.org/x/xerrors" ) // PostgreSQL oids for common types @@ -625,11 +624,11 @@ type scanPlanBinaryInt16 struct{} func (scanPlanBinaryInt16) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { if src == nil { - return errors.Errorf("cannot scan null into %T", dst) + return fmt.Errorf("cannot scan null into %T", dst) } if len(src) != 2 { - return errors.Errorf("invalid length for int2: %v", len(src)) + return fmt.Errorf("invalid length for int2: %v", len(src)) } if p, ok := (dst).(*int16); ok { @@ -645,11 +644,11 @@ type scanPlanBinaryInt32 struct{} func (scanPlanBinaryInt32) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { if src == nil { - return errors.Errorf("cannot scan null into %T", dst) + return fmt.Errorf("cannot scan null into %T", dst) } if len(src) != 4 { - return errors.Errorf("invalid length for int4: %v", len(src)) + return fmt.Errorf("invalid length for int4: %v", len(src)) } if p, ok := (dst).(*int32); ok { @@ -665,11 +664,11 @@ type scanPlanBinaryInt64 struct{} func (scanPlanBinaryInt64) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { if src == nil { - return errors.Errorf("cannot scan null into %T", dst) + return fmt.Errorf("cannot scan null into %T", dst) } if len(src) != 8 { - return errors.Errorf("invalid length for int8: %v", len(src)) + return fmt.Errorf("invalid length for int8: %v", len(src)) } if p, ok := (dst).(*int64); ok { @@ -685,11 +684,11 @@ type scanPlanBinaryFloat32 struct{} func (scanPlanBinaryFloat32) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { if src == nil { - return errors.Errorf("cannot scan null into %T", dst) + return fmt.Errorf("cannot scan null into %T", dst) } if len(src) != 4 { - return errors.Errorf("invalid length for int4: %v", len(src)) + return fmt.Errorf("invalid length for int4: %v", len(src)) } if p, ok := (dst).(*float32); ok { @@ -706,11 +705,11 @@ type scanPlanBinaryFloat64 struct{} func (scanPlanBinaryFloat64) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { if src == nil { - return errors.Errorf("cannot scan null into %T", dst) + return fmt.Errorf("cannot scan null into %T", dst) } if len(src) != 8 { - return errors.Errorf("invalid length for int8: %v", len(src)) + return fmt.Errorf("invalid length for int8: %v", len(src)) } if p, ok := (dst).(*float64); ok { @@ -739,7 +738,7 @@ type scanPlanString struct{} func (scanPlanString) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { if src == nil { - return errors.Errorf("cannot scan null into %T", dst) + return fmt.Errorf("cannot scan null into %T", dst) } if p, ok := (dst).(*string); ok { @@ -841,7 +840,7 @@ func scanUnknownType(oid uint32, formatCode int16, buf []byte, dest interface{}) switch dest := dest.(type) { case *string: if formatCode == BinaryFormatCode { - return errors.Errorf("unknown oid %d in binary format cannot be scanned into %T", oid, dest) + return fmt.Errorf("unknown oid %d in binary format cannot be scanned into %T", oid, dest) } *dest = string(buf) return nil @@ -852,7 +851,7 @@ func scanUnknownType(oid uint32, formatCode int16, buf []byte, dest interface{}) if nextDst, retry := GetAssignToDstType(dest); retry { return scanUnknownType(oid, formatCode, buf, nextDst) } - return errors.Errorf("unknown oid %d cannot be scanned into %T", oid, dest) + return fmt.Errorf("unknown oid %d cannot be scanned into %T", oid, dest) } } diff --git a/pgtype_test.go b/pgtype_test.go index 32ce0a99..f46ec12a 100644 --- a/pgtype_test.go +++ b/pgtype_test.go @@ -2,6 +2,7 @@ package pgtype_test import ( "bytes" + "errors" "net" "testing" @@ -11,7 +12,6 @@ import ( _ "github.com/lib/pq" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - errors "golang.org/x/xerrors" ) // Test for renamed types diff --git a/pguint32.go b/pguint32.go index a245d2c9..a0e88ca2 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/pgio" - errors "golang.org/x/xerrors" ) // 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 errors.Errorf("%d is less than minimum value for pguint32", value) + return fmt.Errorf("%d is less than minimum value for pguint32", value) } if value > math.MaxUint32 { - return errors.Errorf("%d is greater than maximum value for pguint32", value) + return fmt.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 errors.Errorf("cannot convert %v to pguint32", value) + return fmt.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 errors.Errorf("cannot assign %v into %T", src, dst) + return fmt.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 errors.Errorf("invalid length: %v", len(src)) + return fmt.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 errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/point.go b/point.go index 8e6bacf2..0c799106 100644 --- a/point.go +++ b/point.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Vec2 struct { @@ -28,7 +27,7 @@ func (dst *Point) Set(src interface{}) error { dst.Status = Null return nil } - err := errors.Errorf("cannot convert %v to Point", src) + err := fmt.Errorf("cannot convert %v to Point", src) var p *Point switch value := src.(type) { case string: @@ -51,14 +50,14 @@ func parsePoint(src []byte) (*Point, error) { } if len(src) < 5 { - return nil, errors.Errorf("invalid length for point: %v", len(src)) + return nil, fmt.Errorf("invalid length for point: %v", len(src)) } if src[0] == '"' && src[len(src)-1] == '"' { src = src[1 : len(src)-1] } parts := strings.SplitN(string(src[1:len(src)-1]), ",", 2) if len(parts) < 2 { - return nil, errors.Errorf("invalid format for point") + return nil, fmt.Errorf("invalid format for point") } x, err := strconv.ParseFloat(parts[0], 64) @@ -86,7 +85,7 @@ func (dst Point) Get() interface{} { } func (src *Point) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Point) DecodeText(ci *ConnInfo, src []byte) error { @@ -96,12 +95,12 @@ func (dst *Point) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return errors.Errorf("invalid length for point: %v", len(src)) + return fmt.Errorf("invalid length for point: %v", len(src)) } parts := strings.SplitN(string(src[1:len(src)-1]), ",", 2) if len(parts) < 2 { - return errors.Errorf("invalid format for point") + return fmt.Errorf("invalid format for point") } x, err := strconv.ParseFloat(parts[0], 64) @@ -125,7 +124,7 @@ func (dst *Point) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 16 { - return errors.Errorf("invalid length for point: %v", len(src)) + return fmt.Errorf("invalid length for point: %v", len(src)) } x := binary.BigEndian.Uint64(src) @@ -181,7 +180,7 @@ func (dst *Point) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/polygon.go b/polygon.go index 5124af7f..207cadc0 100644 --- a/polygon.go +++ b/polygon.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Polygon struct { @@ -28,7 +27,7 @@ func (dst *Polygon) Set(src interface{}) error { dst.Status = Null return nil } - err := errors.Errorf("cannot convert %v to Polygon", src) + err := fmt.Errorf("cannot convert %v to Polygon", src) var p *Polygon switch value := src.(type) { case string: @@ -61,7 +60,7 @@ func float64ToPolygon(src []float64) (*Polygon, error) { } if len(src)%2 != 0 { p.Status = Undefined - return p, errors.Errorf("invalid length for polygon: %v", len(src)) + return p, fmt.Errorf("invalid length for polygon: %v", len(src)) } p.Status = Present p.P = make([]Vec2, 0) @@ -83,7 +82,7 @@ func (dst Polygon) Get() interface{} { } func (src *Polygon) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Polygon) DecodeText(ci *ConnInfo, src []byte) error { @@ -93,7 +92,7 @@ func (dst *Polygon) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 7 { - return errors.Errorf("invalid length for Polygon: %v", len(src)) + return fmt.Errorf("invalid length for Polygon: %v", len(src)) } points := make([]Vec2, 0) @@ -135,14 +134,14 @@ func (dst *Polygon) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return errors.Errorf("invalid length for Polygon: %v", len(src)) + return fmt.Errorf("invalid length for Polygon: %v", len(src)) } pointCount := int(binary.BigEndian.Uint32(src)) rp := 4 if 4+pointCount*16 != len(src) { - return errors.Errorf("invalid length for Polygon with %d points: %v", pointCount, len(src)) + return fmt.Errorf("invalid length for Polygon with %d points: %v", pointCount, len(src)) } points := make([]Vec2, pointCount) @@ -218,7 +217,7 @@ func (dst *Polygon) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/qchar.go b/qchar.go index 93964058..574f6066 100644 --- a/qchar.go +++ b/qchar.go @@ -1,10 +1,9 @@ package pgtype import ( + "fmt" "math" "strconv" - - errors "golang.org/x/xerrors" ) // QChar is for PostgreSQL's special 8-bit-only "char" type more akin to the C @@ -41,59 +40,59 @@ func (dst *QChar) Set(src interface{}) error { *dst = QChar{Int: value, Status: Present} case uint8: if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int16: if value < math.MinInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint16: if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int32: if value < math.MinInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint32: if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int64: if value < math.MinInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint64: if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case int: if value < math.MinInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case uint: if value > math.MaxInt8 { - return errors.Errorf("%d is greater than maximum value for QChar", value) + return fmt.Errorf("%d is greater than maximum value for QChar", value) } *dst = QChar{Int: int8(value), Status: Present} case string: @@ -106,7 +105,7 @@ func (dst *QChar) Set(src interface{}) error { if originalSrc, ok := underlyingNumberType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to QChar", value) + return fmt.Errorf("cannot convert %v to QChar", value) } return nil @@ -134,7 +133,7 @@ func (dst *QChar) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 1 { - return errors.Errorf(`invalid length for "char": %v`, len(src)) + return fmt.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 35b80ced..e999f6a9 100644 --- a/range.go +++ b/range.go @@ -3,8 +3,7 @@ package pgtype import ( "bytes" "encoding/binary" - - errors "golang.org/x/xerrors" + "fmt" ) type BoundType byte @@ -41,7 +40,7 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { r, _, err := buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid lower bound: %v", err) + return nil, fmt.Errorf("invalid lower bound: %v", err) } switch r { case '(': @@ -49,12 +48,12 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { case '[': utr.LowerType = Inclusive default: - return nil, errors.Errorf("missing lower bound, instead got: %v", string(r)) + return nil, fmt.Errorf("missing lower bound, instead got: %v", string(r)) } r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid lower value: %v", err) + return nil, fmt.Errorf("invalid lower value: %v", err) } buf.UnreadRune() @@ -63,21 +62,21 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { } else { utr.Lower, err = rangeParseValue(buf) if err != nil { - return nil, errors.Errorf("invalid lower value: %v", err) + return nil, fmt.Errorf("invalid lower value: %v", err) } } r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("missing range separator: %v", err) + return nil, fmt.Errorf("missing range separator: %v", err) } if r != ',' { - return nil, errors.Errorf("missing range separator: %v", r) + return nil, fmt.Errorf("missing range separator: %v", r) } r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("invalid upper value: %v", err) + return nil, fmt.Errorf("invalid upper value: %v", err) } if r == ')' || r == ']' { @@ -86,12 +85,12 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { buf.UnreadRune() utr.Upper, err = rangeParseValue(buf) if err != nil { - return nil, errors.Errorf("invalid upper value: %v", err) + return nil, fmt.Errorf("invalid upper value: %v", err) } r, _, err = buf.ReadRune() if err != nil { - return nil, errors.Errorf("missing upper bound: %v", err) + return nil, fmt.Errorf("missing upper bound: %v", err) } switch r { case ')': @@ -99,14 +98,14 @@ func ParseUntypedTextRange(src string) (*UntypedTextRange, error) { case ']': utr.UpperType = Inclusive default: - return nil, errors.Errorf("missing upper bound, instead got: %v", string(r)) + return nil, fmt.Errorf("missing upper bound, instead got: %v", string(r)) } } skipWhitespace(buf) if buf.Len() > 0 { - return nil, errors.Errorf("unexpected trailing data: %v", buf.String()) + return nil, fmt.Errorf("unexpected trailing data: %v", buf.String()) } return utr, nil @@ -202,7 +201,7 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { ubr := &UntypedBinaryRange{} if len(src) == 0 { - return nil, errors.Errorf("range too short: %v", len(src)) + return nil, fmt.Errorf("range too short: %v", len(src)) } rangeType := src[0] @@ -210,7 +209,7 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { if rangeType&emptyMask > 0 { if len(src[rp:]) > 0 { - return nil, errors.Errorf("unexpected trailing bytes parsing empty range: %v", len(src[rp:])) + return nil, fmt.Errorf("unexpected trailing bytes parsing empty range: %v", len(src[rp:])) } ubr.LowerType = Empty ubr.UpperType = Empty @@ -235,13 +234,13 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { if ubr.LowerType == Unbounded && ubr.UpperType == Unbounded { if len(src[rp:]) > 0 { - return nil, errors.Errorf("unexpected trailing bytes parsing unbounded range: %v", len(src[rp:])) + return nil, fmt.Errorf("unexpected trailing bytes parsing unbounded range: %v", len(src[rp:])) } return ubr, nil } if len(src[rp:]) < 4 { - return nil, errors.Errorf("too few bytes for size: %v", src[rp:]) + return nil, fmt.Errorf("too few bytes for size: %v", src[rp:]) } valueLen := int(binary.BigEndian.Uint32(src[rp:])) rp += 4 @@ -254,14 +253,14 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { } else { ubr.Upper = val if len(src[rp:]) > 0 { - return nil, errors.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) + return nil, fmt.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) } return ubr, nil } if ubr.UpperType != Unbounded { if len(src[rp:]) < 4 { - return nil, errors.Errorf("too few bytes for size: %v", src[rp:]) + return nil, fmt.Errorf("too few bytes for size: %v", src[rp:]) } valueLen := int(binary.BigEndian.Uint32(src[rp:])) rp += 4 @@ -270,7 +269,7 @@ func ParseUntypedBinaryRange(src []byte) (*UntypedBinaryRange, error) { } if len(src[rp:]) > 0 { - return nil, errors.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) + return nil, fmt.Errorf("unexpected trailing bytes parsing range: %v", len(src[rp:])) } return ubr, nil diff --git a/record.go b/record.go index 7899a881..718c3570 100644 --- a/record.go +++ b/record.go @@ -1,9 +1,8 @@ package pgtype import ( + "fmt" "reflect" - - errors "golang.org/x/xerrors" ) // Record is the generic PostgreSQL record type such as is created with the @@ -33,7 +32,7 @@ func (dst *Record) Set(src interface{}) error { case []Value: *dst = Record{Fields: value, Status: Present} default: - return errors.Errorf("cannot convert %v to Record", src) + return fmt.Errorf("cannot convert %v to Record", src) } return nil @@ -68,13 +67,13 @@ func (src *Record) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func prepareNewBinaryDecoder(ci *ConnInfo, fieldOID uint32, v *Value) (BinaryDecoder, error) { @@ -83,11 +82,11 @@ func prepareNewBinaryDecoder(ci *ConnInfo, fieldOID uint32, v *Value) (BinaryDec if dt, ok := ci.DataTypeForOID(fieldOID); ok { binaryDecoder, _ = dt.Value.(BinaryDecoder) } else { - return nil, errors.Errorf("unknown oid while decoding record: %v", fieldOID) + return nil, fmt.Errorf("unknown oid while decoding record: %v", fieldOID) } if binaryDecoder == nil { - return nil, errors.Errorf("no binary decoder registered for: %v", fieldOID) + return nil, fmt.Errorf("no binary decoder registered for: %v", fieldOID) } // Duplicate struct to scan into diff --git a/text.go b/text.go index 4c9e4a21..6b01d1b4 100644 --- a/text.go +++ b/text.go @@ -3,8 +3,7 @@ package pgtype import ( "database/sql/driver" "encoding/json" - - errors "golang.org/x/xerrors" + "fmt" ) type Text struct { @@ -44,7 +43,7 @@ func (dst *Text) Set(src interface{}) error { if originalSrc, ok := underlyingStringType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Text", value) + return fmt.Errorf("cannot convert %v to Text", value) } return nil @@ -76,13 +75,13 @@ func (src *Text) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (Text) PreferredResultFormat() int16 { @@ -138,7 +137,7 @@ func (dst *Text) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/text_array.go b/text_array.go index afdc507b..2461966b 100644 --- a/text_array.go +++ b/text_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type TextArray struct { @@ -96,7 +96,7 @@ func (dst *TextArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for TextArray", src) + return fmt.Errorf("cannot find dimensions of %v for TextArray", src) } if elementsLength == 0 { *dst = TextArray{Status: Present} @@ -106,7 +106,7 @@ func (dst *TextArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to TextArray", src) + return fmt.Errorf("cannot convert %v to TextArray", src) } *dst = TextArray{ @@ -137,7 +137,7 @@ func (dst *TextArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to TextArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to TextArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -155,7 +155,7 @@ func (dst *TextArray) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -168,10 +168,10 @@ func (dst *TextArray) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to TextArray") + return 0, fmt.Errorf("cannot convert all values to TextArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in TextArray", err) + return 0, fmt.Errorf("%v in TextArray", err) } index++ @@ -233,7 +233,7 @@ func (src *TextArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -248,7 +248,7 @@ func (src *TextArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -256,7 +256,7 @@ func (src *TextArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *TextArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -272,7 +272,7 @@ func (src *TextArray) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -290,14 +290,14 @@ func (src *TextArray) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from TextArray") + return 0, fmt.Errorf("cannot assign all values from TextArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from TextArray") + return 0, fmt.Errorf("cannot assign all values from TextArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -456,7 +456,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, errors.Errorf("unable to find oid for type name %v", "text") + return nil, fmt.Errorf("unable to find oid for type name %v", "text") } for i := range src.Elements { @@ -500,7 +500,7 @@ func (dst *TextArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/tid.go b/tid.go index f7b80f94..4bb57f64 100644 --- a/tid.go +++ b/tid.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) // TID is PostgreSQL's Tuple Identifier type. @@ -29,7 +28,7 @@ type TID struct { } func (dst *TID) Set(src interface{}) error { - return errors.Errorf("cannot convert %v to TID", src) + return fmt.Errorf("cannot convert %v to TID", src) } func (dst TID) Get() interface{} { @@ -53,11 +52,11 @@ func (src *TID) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } } - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *TID) DecodeText(ci *ConnInfo, src []byte) error { @@ -67,12 +66,12 @@ func (dst *TID) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) < 5 { - return errors.Errorf("invalid length for tid: %v", len(src)) + return fmt.Errorf("invalid length for tid: %v", len(src)) } parts := strings.SplitN(string(src[1:len(src)-1]), ",", 2) if len(parts) < 2 { - return errors.Errorf("invalid format for tid") + return fmt.Errorf("invalid format for tid") } blockNumber, err := strconv.ParseUint(parts[0], 10, 32) @@ -96,7 +95,7 @@ func (dst *TID) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 6 { - return errors.Errorf("invalid length for tid: %v", len(src)) + return fmt.Errorf("invalid length for tid: %v", len(src)) } *dst = TID{ @@ -148,7 +147,7 @@ func (dst *TID) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/time.go b/time.go index 237c4b5b..f7a28870 100644 --- a/time.go +++ b/time.go @@ -8,7 +8,6 @@ import ( "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) // Time represents the PostgreSQL time type. The PostgreSQL time is a time of day without time zone. @@ -52,7 +51,7 @@ func (dst *Time) Set(src interface{}) error { if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Time", value) + return fmt.Errorf("cannot convert %v to Time", value) } return nil @@ -77,7 +76,7 @@ func (src *Time) AssignTo(dst interface{}) error { // 24:00:00 is max allowed time in PostgreSQL, but time.Time will normalize that to 00:00:00 the next day. var maxRepresentableByTime int64 = 24*60*60*1000000 - 1 if src.Microseconds > maxRepresentableByTime { - return errors.Errorf("%d microseconds cannot be represented as time.Time", src.Microseconds) + return fmt.Errorf("%d microseconds cannot be represented as time.Time", src.Microseconds) } usec := src.Microseconds @@ -94,13 +93,13 @@ func (src *Time) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } // DecodeText decodes from src into dst. @@ -113,24 +112,24 @@ func (dst *Time) DecodeText(ci *ConnInfo, src []byte) error { s := string(src) if len(s) < 8 { - return errors.Errorf("cannot decode %v into Time", s) + return fmt.Errorf("cannot decode %v into Time", s) } hours, err := strconv.ParseInt(s[0:2], 10, 64) if err != nil { - return errors.Errorf("cannot decode %v into Time", s) + return fmt.Errorf("cannot decode %v into Time", s) } usec := hours * microsecondsPerHour minutes, err := strconv.ParseInt(s[3:5], 10, 64) if err != nil { - return errors.Errorf("cannot decode %v into Time", s) + return fmt.Errorf("cannot decode %v into Time", s) } usec += minutes * microsecondsPerMinute seconds, err := strconv.ParseInt(s[6:8], 10, 64) if err != nil { - return errors.Errorf("cannot decode %v into Time", s) + return fmt.Errorf("cannot decode %v into Time", s) } usec += seconds * microsecondsPerSecond @@ -138,7 +137,7 @@ func (dst *Time) DecodeText(ci *ConnInfo, src []byte) error { fraction := s[9:] n, err := strconv.ParseInt(fraction, 10, 64) if err != nil { - return errors.Errorf("cannot decode %v into Time", s) + return fmt.Errorf("cannot decode %v into Time", s) } for i := len(fraction); i < 6; i++ { @@ -161,7 +160,7 @@ func (dst *Time) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return errors.Errorf("invalid length for time: %v", len(src)) + return fmt.Errorf("invalid length for time: %v", len(src)) } usec := int64(binary.BigEndian.Uint64(src)) @@ -223,7 +222,7 @@ func (dst *Time) Scan(src interface{}) error { return dst.Set(src) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/timestamp.go b/timestamp.go index 0e127695..46644115 100644 --- a/timestamp.go +++ b/timestamp.go @@ -3,10 +3,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) const pgTimestampFormat = "2006-01-02 15:04:05.999999999" @@ -52,7 +52,7 @@ func (dst *Timestamp) Set(src interface{}) error { if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Timestamp", value) + return fmt.Errorf("cannot convert %v to Timestamp", value) } return nil @@ -78,7 +78,7 @@ func (src *Timestamp) AssignTo(dst interface{}) error { switch v := dst.(type) { case *time.Time: if src.InfinityModifier != None { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } *v = src.Time return nil @@ -86,13 +86,13 @@ func (src *Timestamp) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } // DecodeText decodes from src into dst. The decoded time is considered to @@ -130,7 +130,7 @@ func (dst *Timestamp) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return errors.Errorf("invalid length for timestamp: %v", len(src)) + return fmt.Errorf("invalid length for timestamp: %v", len(src)) } microsecSinceY2K := int64(binary.BigEndian.Uint64(src)) @@ -159,7 +159,7 @@ func (src Timestamp) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } if src.Time.Location() != time.UTC { - return nil, errors.Errorf("cannot encode non-UTC time into timestamp") + return nil, fmt.Errorf("cannot encode non-UTC time into timestamp") } var s string @@ -186,7 +186,7 @@ func (src Timestamp) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, errUndefined } if src.Time.Location() != time.UTC { - return nil, errors.Errorf("cannot encode non-UTC time into timestamp") + return nil, fmt.Errorf("cannot encode non-UTC time into timestamp") } var microsecSinceY2K int64 @@ -222,7 +222,7 @@ func (dst *Timestamp) Scan(src interface{}) error { return nil } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/timestamp_array.go b/timestamp_array.go index 5256f185..e12481e3 100644 --- a/timestamp_array.go +++ b/timestamp_array.go @@ -5,11 +5,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type TimestampArray struct { @@ -97,7 +97,7 @@ func (dst *TimestampArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for TimestampArray", src) + return fmt.Errorf("cannot find dimensions of %v for TimestampArray", src) } if elementsLength == 0 { *dst = TimestampArray{Status: Present} @@ -107,7 +107,7 @@ func (dst *TimestampArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to TimestampArray", src) + return fmt.Errorf("cannot convert %v to TimestampArray", src) } *dst = TimestampArray{ @@ -138,7 +138,7 @@ func (dst *TimestampArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to TimestampArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to TimestampArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -156,7 +156,7 @@ func (dst *TimestampArray) setRecursive(value reflect.Value, index, dimension in valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -169,10 +169,10 @@ func (dst *TimestampArray) setRecursive(value reflect.Value, index, dimension in return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to TimestampArray") + return 0, fmt.Errorf("cannot convert all values to TimestampArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in TimestampArray", err) + return 0, fmt.Errorf("%v in TimestampArray", err) } index++ @@ -234,7 +234,7 @@ func (src *TimestampArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -249,7 +249,7 @@ func (src *TimestampArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -257,7 +257,7 @@ func (src *TimestampArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *TimestampArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -273,7 +273,7 @@ func (src *TimestampArray) assignToRecursive(value reflect.Value, index, dimensi if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -291,14 +291,14 @@ func (src *TimestampArray) assignToRecursive(value reflect.Value, index, dimensi return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from TimestampArray") + return 0, fmt.Errorf("cannot assign all values from TimestampArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from TimestampArray") + return 0, fmt.Errorf("cannot assign all values from TimestampArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -457,7 +457,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, errors.Errorf("unable to find oid for type name %v", "timestamp") + return nil, fmt.Errorf("unable to find oid for type name %v", "timestamp") } for i := range src.Elements { @@ -501,7 +501,7 @@ func (dst *TimestampArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/timestamptz.go b/timestamptz.go index a79bd66e..e0743060 100644 --- a/timestamptz.go +++ b/timestamptz.go @@ -4,10 +4,10 @@ import ( "database/sql/driver" "encoding/binary" "encoding/json" + "fmt" "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) const pgTimestamptzHourFormat = "2006-01-02 15:04:05.999999999Z07" @@ -54,7 +54,7 @@ func (dst *Timestamptz) Set(src interface{}) error { if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to Timestamptz", value) + return fmt.Errorf("cannot convert %v to Timestamptz", value) } return nil @@ -80,7 +80,7 @@ func (src *Timestamptz) AssignTo(dst interface{}) error { switch v := dst.(type) { case *time.Time: if src.InfinityModifier != None { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } *v = src.Time return nil @@ -88,13 +88,13 @@ func (src *Timestamptz) AssignTo(dst interface{}) error { if nextDst, retry := GetAssignToDstType(dst); retry { return src.AssignTo(nextDst) } - return errors.Errorf("unable to assign to %T", dst) + return fmt.Errorf("unable to assign to %T", dst) } case Null: return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (dst *Timestamptz) DecodeText(ci *ConnInfo, src []byte) error { @@ -137,7 +137,7 @@ func (dst *Timestamptz) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 8 { - return errors.Errorf("invalid length for timestamptz: %v", len(src)) + return fmt.Errorf("invalid length for timestamptz: %v", len(src)) } microsecSinceY2K := int64(binary.BigEndian.Uint64(src)) @@ -219,7 +219,7 @@ func (dst *Timestamptz) Scan(src interface{}) error { return nil } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/timestamptz_array.go b/timestamptz_array.go index 47408c02..a3b4b263 100644 --- a/timestamptz_array.go +++ b/timestamptz_array.go @@ -5,11 +5,11 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "time" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type TimestamptzArray struct { @@ -97,7 +97,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for TimestamptzArray", src) + return fmt.Errorf("cannot find dimensions of %v for TimestamptzArray", src) } if elementsLength == 0 { *dst = TimestamptzArray{Status: Present} @@ -107,7 +107,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to TimestamptzArray", src) + return fmt.Errorf("cannot convert %v to TimestamptzArray", src) } *dst = TimestamptzArray{ @@ -138,7 +138,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to TimestamptzArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to TimestamptzArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -156,7 +156,7 @@ func (dst *TimestamptzArray) setRecursive(value reflect.Value, index, dimension valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -169,10 +169,10 @@ func (dst *TimestamptzArray) setRecursive(value reflect.Value, index, dimension return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to TimestamptzArray") + return 0, fmt.Errorf("cannot convert all values to TimestamptzArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in TimestamptzArray", err) + return 0, fmt.Errorf("%v in TimestamptzArray", err) } index++ @@ -234,7 +234,7 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -249,7 +249,7 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -257,7 +257,7 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *TimestamptzArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -273,7 +273,7 @@ func (src *TimestamptzArray) assignToRecursive(value reflect.Value, index, dimen if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -291,14 +291,14 @@ func (src *TimestamptzArray) assignToRecursive(value reflect.Value, index, dimen return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from TimestamptzArray") + return 0, fmt.Errorf("cannot assign all values from TimestamptzArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from TimestamptzArray") + return 0, fmt.Errorf("cannot assign all values from TimestamptzArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -457,7 +457,7 @@ func (src TimestamptzArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, erro if dt, ok := ci.DataTypeForName("timestamptz"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "timestamptz") + return nil, fmt.Errorf("unable to find oid for type name %v", "timestamptz") } for i := range src.Elements { @@ -501,7 +501,7 @@ func (dst *TimestamptzArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/tsrange.go b/tsrange.go index 6ca12aed..19ecf446 100644 --- a/tsrange.go +++ b/tsrange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" + "fmt" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Tsrange struct { @@ -30,7 +30,7 @@ func (dst *Tsrange) Set(src interface{}) error { case string: return dst.DecodeText(nil, []byte(value)) default: - return errors.Errorf("cannot convert %v to Tsrange", src) + return fmt.Errorf("cannot convert %v to Tsrange", src) } return nil @@ -48,7 +48,7 @@ func (dst Tsrange) Get() interface{} { } func (src *Tsrange) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Tsrange) DecodeText(ci *ConnInfo, src []byte) error { @@ -137,7 +137,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) + return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -147,7 +147,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -158,7 +158,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -168,7 +168,7 @@ func (src Tsrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) + return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -192,7 +192,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) + return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -202,7 +202,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) + return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -218,7 +218,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -233,7 +233,7 @@ func (src Tsrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -258,7 +258,7 @@ func (dst *Tsrange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/tsrange_array.go b/tsrange_array.go index 15053f75..c64048eb 100644 --- a/tsrange_array.go +++ b/tsrange_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type TsrangeArray struct { @@ -58,7 +58,7 @@ func (dst *TsrangeArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for TsrangeArray", src) + return fmt.Errorf("cannot find dimensions of %v for TsrangeArray", src) } if elementsLength == 0 { *dst = TsrangeArray{Status: Present} @@ -68,7 +68,7 @@ func (dst *TsrangeArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to TsrangeArray", src) + return fmt.Errorf("cannot convert %v to TsrangeArray", src) } *dst = TsrangeArray{ @@ -99,7 +99,7 @@ func (dst *TsrangeArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to TsrangeArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to TsrangeArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -117,7 +117,7 @@ func (dst *TsrangeArray) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -130,10 +130,10 @@ func (dst *TsrangeArray) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to TsrangeArray") + return 0, fmt.Errorf("cannot convert all values to TsrangeArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in TsrangeArray", err) + return 0, fmt.Errorf("%v in TsrangeArray", err) } index++ @@ -186,7 +186,7 @@ func (src *TsrangeArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -201,7 +201,7 @@ func (src *TsrangeArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -209,7 +209,7 @@ func (src *TsrangeArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *TsrangeArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -225,7 +225,7 @@ func (src *TsrangeArray) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -243,14 +243,14 @@ func (src *TsrangeArray) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from TsrangeArray") + return 0, fmt.Errorf("cannot assign all values from TsrangeArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from TsrangeArray") + return 0, fmt.Errorf("cannot assign all values from TsrangeArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -409,7 +409,7 @@ func (src TsrangeArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("tsrange"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "tsrange") + return nil, fmt.Errorf("unable to find oid for type name %v", "tsrange") } for i := range src.Elements { @@ -453,7 +453,7 @@ func (dst *TsrangeArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/tstzrange.go b/tstzrange.go index 1b05c3ea..25576308 100644 --- a/tstzrange.go +++ b/tstzrange.go @@ -2,9 +2,9 @@ package pgtype import ( "database/sql/driver" + "fmt" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Tstzrange struct { @@ -30,7 +30,7 @@ func (dst *Tstzrange) Set(src interface{}) error { case string: return dst.DecodeText(nil, []byte(value)) default: - return errors.Errorf("cannot convert %v to Tstzrange", src) + return fmt.Errorf("cannot convert %v to Tstzrange", src) } return nil @@ -48,7 +48,7 @@ func (dst Tstzrange) Get() interface{} { } func (src *Tstzrange) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *Tstzrange) DecodeText(ci *ConnInfo, src []byte) error { @@ -137,7 +137,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, "empty"...), nil default: - return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) + return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -147,7 +147,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -158,7 +158,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -168,7 +168,7 @@ func (src Tstzrange) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { case Inclusive: buf = append(buf, ']') default: - return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) + return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -192,7 +192,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { case Empty: return append(buf, emptyMask), nil default: - return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) + return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -202,7 +202,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { rangeType |= upperUnboundedMask case Exclusive: default: - return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) + return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -218,7 +218,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -233,7 +233,7 @@ func (src Tstzrange) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { return nil, err } if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -258,7 +258,7 @@ func (dst *Tstzrange) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/tstzrange_array.go b/tstzrange_array.go index 6d9bfe3b..a216820a 100644 --- a/tstzrange_array.go +++ b/tstzrange_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type TstzrangeArray struct { @@ -58,7 +58,7 @@ func (dst *TstzrangeArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for TstzrangeArray", src) + return fmt.Errorf("cannot find dimensions of %v for TstzrangeArray", src) } if elementsLength == 0 { *dst = TstzrangeArray{Status: Present} @@ -68,7 +68,7 @@ func (dst *TstzrangeArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to TstzrangeArray", src) + return fmt.Errorf("cannot convert %v to TstzrangeArray", src) } *dst = TstzrangeArray{ @@ -99,7 +99,7 @@ func (dst *TstzrangeArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to TstzrangeArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to TstzrangeArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -117,7 +117,7 @@ func (dst *TstzrangeArray) setRecursive(value reflect.Value, index, dimension in valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -130,10 +130,10 @@ func (dst *TstzrangeArray) setRecursive(value reflect.Value, index, dimension in return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to TstzrangeArray") + return 0, fmt.Errorf("cannot convert all values to TstzrangeArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in TstzrangeArray", err) + return 0, fmt.Errorf("%v in TstzrangeArray", err) } index++ @@ -186,7 +186,7 @@ func (src *TstzrangeArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -201,7 +201,7 @@ func (src *TstzrangeArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -209,7 +209,7 @@ func (src *TstzrangeArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *TstzrangeArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -225,7 +225,7 @@ func (src *TstzrangeArray) assignToRecursive(value reflect.Value, index, dimensi if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -243,14 +243,14 @@ func (src *TstzrangeArray) assignToRecursive(value reflect.Value, index, dimensi return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from TstzrangeArray") + return 0, fmt.Errorf("cannot assign all values from TstzrangeArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from TstzrangeArray") + return 0, fmt.Errorf("cannot assign all values from TstzrangeArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -409,7 +409,7 @@ func (src TstzrangeArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) if dt, ok := ci.DataTypeForName("tstzrange"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "tstzrange") + return nil, fmt.Errorf("unable to find oid for type name %v", "tstzrange") } for i := range src.Elements { @@ -453,7 +453,7 @@ func (dst *TstzrangeArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.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 52f14592..5788626b 100644 --- a/typed_array.go.erb +++ b/typed_array.go.erb @@ -78,7 +78,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for <%= pgtype_array_type %>", src) + return fmt.Errorf("cannot find dimensions of %v for <%= pgtype_array_type %>", src) } if elementsLength == 0 { *dst = <%= pgtype_array_type %>{Status: Present} @@ -88,7 +88,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to <%= pgtype_array_type %>", src) + return fmt.Errorf("cannot convert %v to <%= pgtype_array_type %>", src) } *dst = <%= pgtype_array_type %> { @@ -119,7 +119,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to <%= pgtype_array_type %>, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to <%= pgtype_array_type %>, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -137,7 +137,7 @@ func (dst *<%= pgtype_array_type %>) setRecursive(value reflect.Value, index, di valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -150,10 +150,10 @@ func (dst *<%= pgtype_array_type %>) setRecursive(value reflect.Value, index, di return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to <%= pgtype_array_type %>") + return 0, fmt.Errorf("cannot convert all values to <%= pgtype_array_type %>") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in <%= pgtype_array_type %>", err) + return 0, fmt.Errorf("%v in <%= pgtype_array_type %>", err) } index++ @@ -206,7 +206,7 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -221,7 +221,7 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -229,7 +229,7 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *<%= pgtype_array_type %>) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -245,7 +245,7 @@ func (src *<%= pgtype_array_type %>) assignToRecursive(value reflect.Value, inde if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -263,14 +263,14 @@ func (src *<%= pgtype_array_type %>) assignToRecursive(value reflect.Value, inde return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr(){ - return 0, errors.Errorf("cannot assign all values from <%= pgtype_array_type %>") + return 0, fmt.Errorf("cannot assign all values from <%= pgtype_array_type %>") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from <%= pgtype_array_type %>") + return 0, fmt.Errorf("cannot assign all values from <%= pgtype_array_type %>") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -432,7 +432,7 @@ func (src <%= pgtype_array_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte if dt, ok := ci.DataTypeForName("<%= element_type_name %>"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "<%= element_type_name %>") + return nil, fmt.Errorf("unable to find oid for type name %v", "<%= element_type_name %>") } for i := range src.Elements { @@ -477,7 +477,7 @@ func (dst *<%= pgtype_array_type %>) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.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 e21b6cda..5625587a 100644 --- a/typed_range.go.erb +++ b/typed_range.go.erb @@ -32,7 +32,7 @@ func (dst *<%= range_type %>) Set(src interface{}) error { case string: return dst.DecodeText(nil, []byte(value)) default: - return errors.Errorf("cannot convert %v to <%= range_type %>", src) + return fmt.Errorf("cannot convert %v to <%= range_type %>", src) } return nil @@ -50,7 +50,7 @@ func (dst <%= range_type %>) Get() interface{} { } func (src *<%= range_type %>) AssignTo(dst interface{}) error { - return errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.Errorf("cannot assign %v to %T", src, dst) } func (dst *<%= range_type %>) DecodeText(ci *ConnInfo, src []byte) error { @@ -139,7 +139,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error case Empty: return append(buf, "empty"...), nil default: - return nil, errors.Errorf("unknown lower bound type %v", src.LowerType) + return nil, fmt.Errorf("unknown lower bound type %v", src.LowerType) } var err error @@ -149,7 +149,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } } @@ -160,7 +160,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error if err != nil { return nil, err } else if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } } @@ -170,7 +170,7 @@ func (src <%= range_type %>) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error case Inclusive: buf = append(buf, ']') default: - return nil, errors.Errorf("unknown upper bound type %v", src.UpperType) + return nil, fmt.Errorf("unknown upper bound type %v", src.UpperType) } return buf, nil @@ -194,7 +194,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err case Empty: return append(buf, emptyMask), nil default: - return nil, errors.Errorf("unknown LowerType: %v", src.LowerType) + return nil, fmt.Errorf("unknown LowerType: %v", src.LowerType) } switch src.UpperType { @@ -204,7 +204,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err rangeType |= upperUnboundedMask case Exclusive: default: - return nil, errors.Errorf("unknown UpperType: %v", src.UpperType) + return nil, fmt.Errorf("unknown UpperType: %v", src.UpperType) } buf = append(buf, rangeType) @@ -220,7 +220,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err return nil, err } if buf == nil { - return nil, errors.Errorf("Lower cannot be null unless LowerType is Unbounded") + return nil, fmt.Errorf("Lower cannot be null unless LowerType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -235,7 +235,7 @@ func (src <%= range_type %>) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, err return nil, err } if buf == nil { - return nil, errors.Errorf("Upper cannot be null unless UpperType is Unbounded") + return nil, fmt.Errorf("Upper cannot be null unless UpperType is Unbounded") } pgio.SetInt32(buf[sp:], int32(len(buf[sp:])-4)) @@ -260,7 +260,7 @@ func (dst *<%= range_type %>) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/uuid.go b/uuid.go index b1681a78..fa0be07f 100644 --- a/uuid.go +++ b/uuid.go @@ -5,8 +5,6 @@ import ( "database/sql/driver" "encoding/hex" "fmt" - - errors "golang.org/x/xerrors" ) type UUID struct { @@ -33,7 +31,7 @@ func (dst *UUID) Set(src interface{}) error { case []byte: if value != nil { if len(value) != 16 { - return errors.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) + return fmt.Errorf("[]byte must be 16 bytes to convert to UUID: %d", len(value)) } *dst = UUID{Status: Present} copy(dst.Bytes[:], value) @@ -56,7 +54,7 @@ func (dst *UUID) Set(src interface{}) error { if originalSrc, ok := underlyingUUIDType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to UUID", value) + return fmt.Errorf("cannot convert %v to UUID", value) } return nil @@ -96,7 +94,7 @@ func (src *UUID) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot assign %v into %T", src, dst) + return fmt.Errorf("cannot assign %v into %T", src, dst) } // parseUUID converts a string UUID in standard form to a byte array. @@ -108,7 +106,7 @@ func parseUUID(src string) (dst [16]byte, err error) { // dashes already stripped, assume valid default: // assume invalid. - return dst, errors.Errorf("cannot parse UUID %v", src) + return dst, fmt.Errorf("cannot parse UUID %v", src) } buf, err := hex.DecodeString(src) @@ -132,7 +130,7 @@ func (dst *UUID) DecodeText(ci *ConnInfo, src []byte) error { } if len(src) != 36 { - return errors.Errorf("invalid length for UUID: %v", len(src)) + return fmt.Errorf("invalid length for UUID: %v", len(src)) } buf, err := parseUUID(string(src)) @@ -151,7 +149,7 @@ func (dst *UUID) DecodeBinary(ci *ConnInfo, src []byte) error { } if len(src) != 16 { - return errors.Errorf("invalid length for UUID: %v", len(src)) + return fmt.Errorf("invalid length for UUID: %v", len(src)) } *dst = UUID{Status: Present} @@ -197,7 +195,7 @@ func (dst *UUID) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. @@ -226,7 +224,7 @@ func (dst *UUID) UnmarshalJSON(src []byte) error { return dst.Set(nil) } if len(src) != 38 { - return errors.Errorf("invalid length for UUID: %v", len(src)) + return fmt.Errorf("invalid length for UUID: %v", len(src)) } return dst.Set(string(src[1 : len(src)-1])) } diff --git a/uuid_array.go b/uuid_array.go index c6970d52..00721ef9 100644 --- a/uuid_array.go +++ b/uuid_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type UUIDArray struct { @@ -134,7 +134,7 @@ func (dst *UUIDArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for UUIDArray", src) + return fmt.Errorf("cannot find dimensions of %v for UUIDArray", src) } if elementsLength == 0 { *dst = UUIDArray{Status: Present} @@ -144,7 +144,7 @@ func (dst *UUIDArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to UUIDArray", src) + return fmt.Errorf("cannot convert %v to UUIDArray", src) } *dst = UUIDArray{ @@ -175,7 +175,7 @@ func (dst *UUIDArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to UUIDArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to UUIDArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -193,7 +193,7 @@ func (dst *UUIDArray) setRecursive(value reflect.Value, index, dimension int) (i valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -206,10 +206,10 @@ func (dst *UUIDArray) setRecursive(value reflect.Value, index, dimension int) (i return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to UUIDArray") + return 0, fmt.Errorf("cannot convert all values to UUIDArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in UUIDArray", err) + return 0, fmt.Errorf("%v in UUIDArray", err) } index++ @@ -289,7 +289,7 @@ func (src *UUIDArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -304,7 +304,7 @@ func (src *UUIDArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -312,7 +312,7 @@ func (src *UUIDArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *UUIDArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -328,7 +328,7 @@ func (src *UUIDArray) assignToRecursive(value reflect.Value, index, dimension in if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -346,14 +346,14 @@ func (src *UUIDArray) assignToRecursive(value reflect.Value, index, dimension in return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from UUIDArray") + return 0, fmt.Errorf("cannot assign all values from UUIDArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from UUIDArray") + return 0, fmt.Errorf("cannot assign all values from UUIDArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -512,7 +512,7 @@ func (src UUIDArray) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { if dt, ok := ci.DataTypeForName("uuid"); ok { arrayHeader.ElementOID = int32(dt.OID) } else { - return nil, errors.Errorf("unable to find oid for type name %v", "uuid") + return nil, fmt.Errorf("unable to find oid for type name %v", "uuid") } for i := range src.Elements { @@ -556,7 +556,7 @@ func (dst *UUIDArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/varbit.go b/varbit.go index 7461bab3..f24dc5bc 100644 --- a/varbit.go +++ b/varbit.go @@ -3,9 +3,9 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type Varbit struct { @@ -15,7 +15,7 @@ type Varbit struct { } func (dst *Varbit) Set(src interface{}) error { - return errors.Errorf("cannot convert %v to Varbit", src) + return fmt.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 errors.Errorf("cannot assign %v to %T", src, dst) + return fmt.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 errors.Errorf("invalid length for varbit: %v", len(src)) + return fmt.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 errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface. diff --git a/varchar_array.go b/varchar_array.go index f3a9b001..8a309a3f 100644 --- a/varchar_array.go +++ b/varchar_array.go @@ -5,10 +5,10 @@ package pgtype import ( "database/sql/driver" "encoding/binary" + "fmt" "reflect" "github.com/jackc/pgio" - errors "golang.org/x/xerrors" ) type VarcharArray struct { @@ -96,7 +96,7 @@ func (dst *VarcharArray) Set(src interface{}) error { dimensions, elementsLength, ok := findDimensionsFromValue(reflectedValue, nil, 0) if !ok { - return errors.Errorf("cannot find dimensions of %v for VarcharArray", src) + return fmt.Errorf("cannot find dimensions of %v for VarcharArray", src) } if elementsLength == 0 { *dst = VarcharArray{Status: Present} @@ -106,7 +106,7 @@ func (dst *VarcharArray) Set(src interface{}) error { if originalSrc, ok := underlyingSliceType(src); ok { return dst.Set(originalSrc) } - return errors.Errorf("cannot convert %v to VarcharArray", src) + return fmt.Errorf("cannot convert %v to VarcharArray", src) } *dst = VarcharArray{ @@ -137,7 +137,7 @@ func (dst *VarcharArray) Set(src interface{}) error { } } if elementCount != len(dst.Elements) { - return errors.Errorf("cannot convert %v to VarcharArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) + return fmt.Errorf("cannot convert %v to VarcharArray, expected %d dst.Elements, but got %d instead", src, len(dst.Elements), elementCount) } } @@ -155,7 +155,7 @@ func (dst *VarcharArray) setRecursive(value reflect.Value, index, dimension int) valueLen := value.Len() if int32(valueLen) != dst.Dimensions[dimension].Length { - return 0, errors.Errorf("multidimensional arrays must have array expressions with matching dimensions") + return 0, fmt.Errorf("multidimensional arrays must have array expressions with matching dimensions") } for i := 0; i < valueLen; i++ { var err error @@ -168,10 +168,10 @@ func (dst *VarcharArray) setRecursive(value reflect.Value, index, dimension int) return index, nil } if !value.CanInterface() { - return 0, errors.Errorf("cannot convert all values to VarcharArray") + return 0, fmt.Errorf("cannot convert all values to VarcharArray") } if err := dst.Elements[index].Set(value.Interface()); err != nil { - return 0, errors.Errorf("%v in VarcharArray", err) + return 0, fmt.Errorf("%v in VarcharArray", err) } index++ @@ -233,7 +233,7 @@ func (src *VarcharArray) AssignTo(dst interface{}) error { switch value.Kind() { case reflect.Array, reflect.Slice: default: - return errors.Errorf("cannot assign %T to %T", src, dst) + return fmt.Errorf("cannot assign %T to %T", src, dst) } if len(src.Elements) == 0 { @@ -248,7 +248,7 @@ func (src *VarcharArray) AssignTo(dst interface{}) error { return err } if elementCount != len(src.Elements) { - return errors.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) + return fmt.Errorf("cannot assign %v, needed to assign %d elements, but only assigned %d", dst, len(src.Elements), elementCount) } return nil @@ -256,7 +256,7 @@ func (src *VarcharArray) AssignTo(dst interface{}) error { return NullAssignTo(dst) } - return errors.Errorf("cannot decode %#v into %T", src, dst) + return fmt.Errorf("cannot decode %#v into %T", src, dst) } func (src *VarcharArray) assignToRecursive(value reflect.Value, index, dimension int) (int, error) { @@ -272,7 +272,7 @@ func (src *VarcharArray) assignToRecursive(value reflect.Value, index, dimension if reflect.Array == kind { typ := value.Type() if typ.Len() != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) + return 0, fmt.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { @@ -290,14 +290,14 @@ func (src *VarcharArray) assignToRecursive(value reflect.Value, index, dimension return index, nil } if len(src.Dimensions) != dimension { - return 0, errors.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) + return 0, fmt.Errorf("incorrect dimensions, expected %d, found %d", len(src.Dimensions), dimension) } if !value.CanAddr() { - return 0, errors.Errorf("cannot assign all values from VarcharArray") + return 0, fmt.Errorf("cannot assign all values from VarcharArray") } addr := value.Addr() if !addr.CanInterface() { - return 0, errors.Errorf("cannot assign all values from VarcharArray") + return 0, fmt.Errorf("cannot assign all values from VarcharArray") } if err := src.Elements[index].AssignTo(addr.Interface()); err != nil { return 0, err @@ -456,7 +456,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, errors.Errorf("unable to find oid for type name %v", "varchar") + return nil, fmt.Errorf("unable to find oid for type name %v", "varchar") } for i := range src.Elements { @@ -500,7 +500,7 @@ func (dst *VarcharArray) Scan(src interface{}) error { return dst.DecodeText(nil, srcCopy) } - return errors.Errorf("cannot scan %T", src) + return fmt.Errorf("cannot scan %T", src) } // Value implements the database/sql/driver Valuer interface.