Use Go 1.13 errors instead of xerrors
This commit is contained in:
+16
-16
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user