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