Use github.com/pkg/errors
This commit is contained in:
+28
-28
@@ -3,13 +3,13 @@ package pgtype
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/jackc/pgx/pgio"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// PostgreSQL internal numeric storage uses 16-bit "digits" with base of 10,000
|
||||
@@ -97,7 +97,7 @@ func (dst *Numeric) Set(src interface{}) error {
|
||||
if originalSrc, ok := underlyingNumberType(src); ok {
|
||||
return dst.Set(originalSrc)
|
||||
}
|
||||
return fmt.Errorf("cannot convert %v to Numeric", value)
|
||||
return errors.Errorf("cannot convert %v to Numeric", value)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -136,10 +136,10 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(bigMaxInt) > 0 {
|
||||
return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
if normalizedInt.Cmp(bigMinInt) < 0 {
|
||||
return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = int(normalizedInt.Int64())
|
||||
case *int8:
|
||||
@@ -148,10 +148,10 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(bigMaxInt8) > 0 {
|
||||
return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
if normalizedInt.Cmp(bigMinInt8) < 0 {
|
||||
return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = int8(normalizedInt.Int64())
|
||||
case *int16:
|
||||
@@ -160,10 +160,10 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(bigMaxInt16) > 0 {
|
||||
return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
if normalizedInt.Cmp(bigMinInt16) < 0 {
|
||||
return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = int16(normalizedInt.Int64())
|
||||
case *int32:
|
||||
@@ -172,10 +172,10 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(bigMaxInt32) > 0 {
|
||||
return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
if normalizedInt.Cmp(bigMinInt32) < 0 {
|
||||
return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = int32(normalizedInt.Int64())
|
||||
case *int64:
|
||||
@@ -184,10 +184,10 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(bigMaxInt64) > 0 {
|
||||
return fmt.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
if normalizedInt.Cmp(bigMinInt64) < 0 {
|
||||
return fmt.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%v is less than minimum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = normalizedInt.Int64()
|
||||
case *uint:
|
||||
@@ -196,9 +196,9 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(big0) < 0 {
|
||||
return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
} else if normalizedInt.Cmp(bigMaxUint) > 0 {
|
||||
return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = uint(normalizedInt.Uint64())
|
||||
case *uint8:
|
||||
@@ -207,9 +207,9 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(big0) < 0 {
|
||||
return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
} else if normalizedInt.Cmp(bigMaxUint8) > 0 {
|
||||
return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = uint8(normalizedInt.Uint64())
|
||||
case *uint16:
|
||||
@@ -218,9 +218,9 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(big0) < 0 {
|
||||
return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
} else if normalizedInt.Cmp(bigMaxUint16) > 0 {
|
||||
return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = uint16(normalizedInt.Uint64())
|
||||
case *uint32:
|
||||
@@ -229,9 +229,9 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(big0) < 0 {
|
||||
return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
} else if normalizedInt.Cmp(bigMaxUint32) > 0 {
|
||||
return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = uint32(normalizedInt.Uint64())
|
||||
case *uint64:
|
||||
@@ -240,9 +240,9 @@ func (src *Numeric) AssignTo(dst interface{}) error {
|
||||
return err
|
||||
}
|
||||
if normalizedInt.Cmp(big0) < 0 {
|
||||
return fmt.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is less than zero for %T", normalizedInt, *v)
|
||||
} else if normalizedInt.Cmp(bigMaxUint64) > 0 {
|
||||
return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
return errors.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
|
||||
}
|
||||
*v = normalizedInt.Uint64()
|
||||
default:
|
||||
@@ -276,7 +276,7 @@ func (dst *Numeric) toBigInt() (*big.Int, error) {
|
||||
remainder := &big.Int{}
|
||||
num.DivMod(num, div, remainder)
|
||||
if remainder.Cmp(big0) != 0 {
|
||||
return nil, fmt.Errorf("cannot convert %v to integer", dst)
|
||||
return nil, errors.Errorf("cannot convert %v to integer", dst)
|
||||
}
|
||||
return num, nil
|
||||
}
|
||||
@@ -328,7 +328,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, fmt.Errorf("%s is not a number", str)
|
||||
return nil, 0, errors.Errorf("%s is not a number", str)
|
||||
}
|
||||
|
||||
return accum, exp, nil
|
||||
@@ -341,7 +341,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
}
|
||||
|
||||
if len(src) < 8 {
|
||||
return fmt.Errorf("numeric incomplete %v", src)
|
||||
return errors.Errorf("numeric incomplete %v", src)
|
||||
}
|
||||
|
||||
rp := 0
|
||||
@@ -361,7 +361,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
rp += 2
|
||||
|
||||
if len(src[rp:]) < int(ndigits)*2 {
|
||||
return fmt.Errorf("numeric incomplete %v", src)
|
||||
return errors.Errorf("numeric incomplete %v", src)
|
||||
}
|
||||
|
||||
accum := &big.Int{}
|
||||
@@ -382,7 +382,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
case 4:
|
||||
mul = bigNBaseX4
|
||||
default:
|
||||
return fmt.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead)
|
||||
return errors.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead)
|
||||
}
|
||||
accum.Mul(accum, mul)
|
||||
}
|
||||
@@ -575,7 +575,7 @@ func (dst *Numeric) Scan(src interface{}) error {
|
||||
return dst.DecodeText(nil, srcCopy)
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot scan %T", src)
|
||||
return errors.Errorf("cannot scan %T", src)
|
||||
}
|
||||
|
||||
// Value implements the database/sql/driver Valuer interface.
|
||||
|
||||
Reference in New Issue
Block a user