mirror of https://github.com/jackc/pgx.git
wrap errors instead of just formatting them
parent
7ebced92b5
commit
89d699c2e8
6
conn.go
6
conn.go
|
@ -475,7 +475,7 @@ optionLoop:
|
|||
if queryRewriter != nil {
|
||||
sql, arguments, err = queryRewriter.RewriteQuery(ctx, c, sql, arguments)
|
||||
if err != nil {
|
||||
return pgconn.CommandTag{}, fmt.Errorf("rewrite query failed: %v", err)
|
||||
return pgconn.CommandTag{}, fmt.Errorf("rewrite query failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -742,7 +742,7 @@ optionLoop:
|
|||
sql, args, err = queryRewriter.RewriteQuery(ctx, c, sql, args)
|
||||
if err != nil {
|
||||
rows := c.getRows(ctx, originalSQL, originalArgs)
|
||||
err = fmt.Errorf("rewrite query failed: %v", err)
|
||||
err = fmt.Errorf("rewrite query failed: %w", err)
|
||||
rows.fatal(err)
|
||||
return rows, err
|
||||
}
|
||||
|
@ -924,7 +924,7 @@ func (c *Conn) SendBatch(ctx context.Context, b *Batch) (br BatchResults) {
|
|||
var err error
|
||||
sql, arguments, err = queryRewriter.RewriteQuery(ctx, c, sql, arguments)
|
||||
if err != nil {
|
||||
return &batchResults{ctx: ctx, conn: c, err: fmt.Errorf("rewrite query failed: %v", err)}
|
||||
return &batchResults{ctx: ctx, conn: c, err: fmt.Errorf("rewrite query failed: %w", err)}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ func (eqb *ExtendedQueryBuilder) Build(m *pgtype.Map, sd *pgconn.StatementDescri
|
|||
for i := range args {
|
||||
err := eqb.appendParam(m, sd.ParamOIDs[i], -1, args[i])
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to encode args[%d]: %v", i, err)
|
||||
err = fmt.Errorf("failed to encode args[%d]: %w", i, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3324,7 +3324,7 @@ func TestSNISupport(t *testing.T) {
|
|||
defer srv.Close()
|
||||
|
||||
if err := srv.Handshake(); err != nil {
|
||||
serverErrChan <- fmt.Errorf("handshake: %v", err)
|
||||
serverErrChan <- fmt.Errorf("handshake: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
|
||||
r, _, err := buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
var explicitDimensions []ArrayDimension
|
||||
|
@ -122,7 +122,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
for {
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
if r == '=' {
|
||||
|
@ -133,12 +133,12 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
|
||||
lower, err := arrayParseInteger(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
if r != ':' {
|
||||
|
@ -147,12 +147,12 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
|
||||
upper, err := arrayParseInteger(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
if r != ']' {
|
||||
|
@ -164,7 +164,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
for {
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
if r == '{' {
|
||||
|
@ -195,7 +195,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
for {
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
switch r {
|
||||
|
@ -214,7 +214,7 @@ func parseUntypedTextArray(src string) (*untypedTextArray, error) {
|
|||
buf.UnreadRune()
|
||||
value, quoted, err := arrayParseValue(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array value: %v", err)
|
||||
return nil, fmt.Errorf("invalid array value: %w", err)
|
||||
}
|
||||
if currentDim == counterDim {
|
||||
implicitDimensions[currentDim].Length++
|
||||
|
|
|
@ -231,7 +231,7 @@ func (w *uint64Wrapper) ScanNumeric(v Numeric) error {
|
|||
|
||||
bi, err := v.toBigInt()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot scan into *uint64: %v", err)
|
||||
return fmt.Errorf("cannot scan into *uint64: %w", err)
|
||||
}
|
||||
|
||||
if !bi.IsUint64() {
|
||||
|
@ -284,7 +284,7 @@ func (w *uintWrapper) ScanNumeric(v Numeric) error {
|
|||
|
||||
bi, err := v.toBigInt()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot scan into *uint: %v", err)
|
||||
return fmt.Errorf("cannot scan into *uint: %w", err)
|
||||
}
|
||||
|
||||
if !bi.IsUint64() {
|
||||
|
|
|
@ -282,17 +282,17 @@ func (scanPlanTextAnyToDateScanner) Scan(src []byte, dst any) error {
|
|||
if match != nil {
|
||||
year, err := strconv.ParseInt(match[1], 10, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("BUG: cannot parse date that regexp matched (year): %v", err)
|
||||
return fmt.Errorf("BUG: cannot parse date that regexp matched (year): %w", err)
|
||||
}
|
||||
|
||||
month, err := strconv.ParseInt(match[2], 10, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %v", err)
|
||||
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %w", err)
|
||||
}
|
||||
|
||||
day, err := strconv.ParseInt(match[3], 10, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %v", err)
|
||||
return fmt.Errorf("BUG: cannot parse date that regexp matched (month): %w", err)
|
||||
}
|
||||
|
||||
// BC matched
|
||||
|
|
|
@ -339,7 +339,7 @@ func parseUntypedTextMultirange(src []byte) ([]string, error) {
|
|||
|
||||
r, _, err := buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid array: %v", err)
|
||||
return nil, fmt.Errorf("invalid array: %w", err)
|
||||
}
|
||||
|
||||
if r != '{' {
|
||||
|
@ -350,7 +350,7 @@ parseValueLoop:
|
|||
for {
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid multirange: %v", err)
|
||||
return nil, fmt.Errorf("invalid multirange: %w", err)
|
||||
}
|
||||
|
||||
switch r {
|
||||
|
@ -361,7 +361,7 @@ parseValueLoop:
|
|||
buf.UnreadRune()
|
||||
value, err := parseRange(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid multirange value: %v", err)
|
||||
return nil, fmt.Errorf("invalid multirange value: %w", err)
|
||||
}
|
||||
elements = append(elements, value)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
|
|||
|
||||
r, _, err := buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid lower bound: %v", err)
|
||||
return nil, fmt.Errorf("invalid lower bound: %w", err)
|
||||
}
|
||||
switch r {
|
||||
case '(':
|
||||
|
@ -53,7 +53,7 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
|
|||
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid lower value: %v", err)
|
||||
return nil, fmt.Errorf("invalid lower value: %w", err)
|
||||
}
|
||||
buf.UnreadRune()
|
||||
|
||||
|
@ -62,13 +62,13 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
|
|||
} else {
|
||||
utr.Lower, err = rangeParseValue(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid lower value: %v", err)
|
||||
return nil, fmt.Errorf("invalid lower value: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("missing range separator: %v", err)
|
||||
return nil, fmt.Errorf("missing range separator: %w", err)
|
||||
}
|
||||
if r != ',' {
|
||||
return nil, fmt.Errorf("missing range separator: %v", r)
|
||||
|
@ -76,7 +76,7 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
|
|||
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid upper value: %v", err)
|
||||
return nil, fmt.Errorf("invalid upper value: %w", err)
|
||||
}
|
||||
|
||||
if r == ')' || r == ']' {
|
||||
|
@ -85,12 +85,12 @@ func parseUntypedTextRange(src string) (*untypedTextRange, error) {
|
|||
buf.UnreadRune()
|
||||
utr.Upper, err = rangeParseValue(buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid upper value: %v", err)
|
||||
return nil, fmt.Errorf("invalid upper value: %w", err)
|
||||
}
|
||||
|
||||
r, _, err = buf.ReadRune()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("missing upper bound: %v", err)
|
||||
return nil, fmt.Errorf("missing upper bound: %w", err)
|
||||
}
|
||||
switch r {
|
||||
case ')':
|
||||
|
|
|
@ -120,7 +120,7 @@ func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value any, buf []byt
|
|||
|
||||
buf, err = lowerPlan.Encode(lower, buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %v", lower, err)
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %w", lower, err)
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, fmt.Errorf("Lower cannot be NULL unless LowerType is Unbounded")
|
||||
|
@ -144,7 +144,7 @@ func (plan *encodePlanRangeCodecRangeValuerToBinary) Encode(value any, buf []byt
|
|||
|
||||
buf, err = upperPlan.Encode(upper, buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %v", upper, err)
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %w", upper, err)
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, fmt.Errorf("Upper cannot be NULL unless UpperType is Unbounded")
|
||||
|
@ -194,7 +194,7 @@ func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value any, buf []byte)
|
|||
|
||||
buf, err = lowerPlan.Encode(lower, buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %v", lower, err)
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %w", lower, err)
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, fmt.Errorf("Lower cannot be NULL unless LowerType is Unbounded")
|
||||
|
@ -215,7 +215,7 @@ func (plan *encodePlanRangeCodecRangeValuerToText) Encode(value any, buf []byte)
|
|||
|
||||
buf, err = upperPlan.Encode(upper, buf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %v", upper, err)
|
||||
return nil, fmt.Errorf("failed to encode %v as element of range: %w", upper, err)
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, fmt.Errorf("Upper cannot be NULL unless UpperType is Unbounded")
|
||||
|
@ -282,7 +282,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target any) erro
|
|||
|
||||
err = lowerPlan.Scan(ubr.Lower, lowerTarget)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot scan into %v from range element: %v", lowerTarget, err)
|
||||
return fmt.Errorf("cannot scan into %v from range element: %w", lowerTarget, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,7 +294,7 @@ func (plan *scanPlanBinaryRangeToRangeScanner) Scan(src []byte, target any) erro
|
|||
|
||||
err = upperPlan.Scan(ubr.Upper, upperTarget)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot scan into %v from range element: %v", upperTarget, err)
|
||||
return fmt.Errorf("cannot scan into %v from range element: %w", upperTarget, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target any) error
|
|||
|
||||
err = lowerPlan.Scan([]byte(utr.Lower), lowerTarget)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot scan into %v from range element: %v", lowerTarget, err)
|
||||
return fmt.Errorf("cannot scan into %v from range element: %w", lowerTarget, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ func (plan *scanPlanTextRangeToRangeScanner) Scan(src []byte, target any) error
|
|||
|
||||
err = upperPlan.Scan([]byte(utr.Upper), upperTarget)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot scan into %v from range element: %v", upperTarget, err)
|
||||
return fmt.Errorf("cannot scan into %v from range element: %w", upperTarget, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -840,7 +840,7 @@ func (r *Rows) Next(dest []driver.Value) error {
|
|||
var err error
|
||||
dest[i], err = r.valueFuncs[i](rv)
|
||||
if err != nil {
|
||||
return fmt.Errorf("convert field %d failed: %v", i, err)
|
||||
return fmt.Errorf("convert field %d failed: %w", i, err)
|
||||
}
|
||||
} else {
|
||||
dest[i] = nil
|
||||
|
|
Loading…
Reference in New Issue