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