Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
57 changes: 2 additions & 55 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
})
}
}