diff --git a/CHANGELOG.md b/CHANGELOG.md index ba15e93..2cad074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [4.2.7] + +### Changed +- Fix error source in QueryData (#180) + ## [4.2.6] ### Changed diff --git a/errors.go b/errors.go index 4558736..2820368 100644 --- a/errors.go +++ b/errors.go @@ -62,38 +62,12 @@ func IsPGXConnectionError(err error) bool { return false } -// IsGenericDownstreamError checks if an error is a generic downstream error -func IsGenericDownstreamError(err error) bool { - if err == nil { - return false - } - - errStr := strings.ToLower(err.Error()) - genericDownstreamErrors := []string{ - "invalid memory address", - "nil pointer dereference", - } - - for _, genericErr := range genericDownstreamErrors { - if strings.Contains(errStr, genericErr) { - return true - } - } - - return false -} - // ClassifyError determines the appropriate error source and type for SQL errors func ClassifyError(err error) (backend.ErrorSource, error) { if err == nil { return backend.ErrorSourcePlugin, nil } - // Check for generic downstream errors first - if IsGenericDownstreamError(err) { - return backend.ErrorSourceDownstream, err - } - // Check for PGX v5 specific connection errors if IsPGXConnectionError(err) { // These are typically downstream connection issues diff --git a/query.go b/query.go index 056aa10..ae52a50 100644 --- a/query.go +++ b/query.go @@ -84,7 +84,7 @@ func (q *DBQuery) Run(ctx context.Context, query *Query, args ...interface{}) (d if errors.Is(err, context.Canceled) { errType = context.Canceled - errSource = backend.ErrorSourcePlugin + errSource = backend.ErrorSourceDownstream } else if IsPGXConnectionError(err) { errType = ErrorPGXLifecycle errSource = backend.ErrorSourceDownstream @@ -322,11 +322,6 @@ func isProcessingDownstreamError(err error) bool { } } - // Check for generic downstream errors - if IsGenericDownstreamError(err) { - return true - } - // Check for PGX connection errors if IsPGXConnectionError(err) { return true diff --git a/query_test.go b/query_test.go index 48aa250..de4834a 100644 --- a/query_test.go +++ b/query_test.go @@ -242,8 +242,8 @@ func TestPGXErrorClassification(t *testing.T) { { name: "nil pointer dereference", errorMsg: "runtime error: invalid memory address or nil pointer dereference", - expectedSource: backend.ErrorSourceDownstream, - expectedIsPGX: false, // Now handled as generic downstream error + expectedSource: backend.ErrorSourcePlugin, + expectedIsPGX: false, }, { name: "connection closed", @@ -297,56 +297,3 @@ func TestPGXErrorClassification(t *testing.T) { }) } } - -func TestIsGenericDownstreamError(t *testing.T) { - tests := []struct { - name string - errorMsg string - expected bool - }{ - { - name: "nil pointer dereference", - errorMsg: "runtime error: invalid memory address or nil pointer dereference", - expected: true, - }, - { - name: "invalid memory address", - errorMsg: "runtime error: invalid memory address", - expected: true, - }, - { - name: "nil pointer dereference uppercase", - errorMsg: "NIL POINTER DEREFERENCE", - expected: true, - }, - { - name: "regular SQL error", - errorMsg: "syntax error at position 1", - expected: false, - }, - { - name: "connection error", - errorMsg: "connection closed", - expected: false, - }, - { - name: "nil error", - errorMsg: "", - expected: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var err error - if tt.errorMsg != "" { - err = errors.New(tt.errorMsg) - } - - result := IsGenericDownstreamError(err) - if result != tt.expected { - t.Errorf("IsGenericDownstreamError(%v) = %v, expected %v", tt.errorMsg, result, tt.expected) - } - }) - } -}