2
0

Use Go 1.13 errors instead of xerrors

This commit is contained in:
Jack Christensen
2021-03-25 09:01:59 -04:00
parent aa89720576
commit dd160540c4
80 changed files with 927 additions and 956 deletions
+16 -16
View File
@@ -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.