From 28ea2cd1905808c0d7d9db0bc573ee4861ef91c6 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 5 Feb 2022 13:05:23 -0600 Subject: [PATCH] Better error messages --- pgtype/array_codec.go | 2 +- pgtype/pgtype.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pgtype/array_codec.go b/pgtype/array_codec.go index 901ea5f7..5a02c435 100644 --- a/pgtype/array_codec.go +++ b/pgtype/array_codec.go @@ -250,7 +250,7 @@ func (c *ArrayCodec) decodeBinary(ci *ConnInfo, arrayOID uint32, src []byte, arr } err = elementScanPlan.Scan(elemSrc, elem) if err != nil { - return err + return fmt.Errorf("failed to scan array element %d: %w", i, err) } } diff --git a/pgtype/pgtype.go b/pgtype/pgtype.go index 571b5bfc..45b9a092 100644 --- a/pgtype/pgtype.go +++ b/pgtype/pgtype.go @@ -489,7 +489,17 @@ type scanPlanFail struct { } func (plan *scanPlanFail) Scan(src []byte, dst interface{}) error { - return fmt.Errorf("cannot scan OID %v in format %v into %T", plan.oid, plan.formatCode, dst) + var format string + switch plan.formatCode { + case TextFormatCode: + format = "text" + case BinaryFormatCode: + format = "binary" + default: + format = fmt.Sprintf("unknown %d", plan.formatCode) + } + + return fmt.Errorf("cannot scan OID %v in %v format into %T", plan.oid, format, dst) } // TryWrapScanPlanFunc is a function that tries to create a wrapper plan for target. If successful it returns a plan