From a71c179ce378f5b18868d744f7ca4b877ac6e5dc Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sun, 10 May 2020 12:28:47 -0500 Subject: [PATCH] Extract nullAssignmentError --- convert.go | 4 ++-- pgtype.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/convert.go b/convert.go index 4fe659b3..47227fd5 100644 --- a/convert.go +++ b/convert.go @@ -369,7 +369,7 @@ func NullAssignTo(dst interface{}) error { // AssignTo dst must always be a pointer if dstPtr.Kind() != reflect.Ptr { - return errors.Errorf("cannot assign NULL to %T", dst) + return &nullAssignmentError{dst: dst} } dstVal := dstPtr.Elem() @@ -380,7 +380,7 @@ func NullAssignTo(dst interface{}) error { return nil } - return errors.Errorf("cannot assign NULL to %T", dst) + return &nullAssignmentError{dst: dst} } var kindTypes map[reflect.Kind]reflect.Type diff --git a/pgtype.go b/pgtype.go index fb60f067..d58be882 100644 --- a/pgtype.go +++ b/pgtype.go @@ -3,6 +3,7 @@ package pgtype import ( "database/sql" "encoding/binary" + "fmt" "math" "net" "reflect" @@ -198,6 +199,14 @@ func (f BinaryEncoderFunc) EncodeBinary(ci *ConnInfo, buf []byte) (newBuf []byte var errUndefined = errors.New("cannot encode status undefined") var errBadStatus = errors.New("invalid status") +type nullAssignmentError struct { + dst interface{} +} + +func (e *nullAssignmentError) Error() string { + return fmt.Sprintf("cannot assign NULL to %T", e.dst) +} + type DataType struct { Value Value