Skip to content

Commit b38c59d

Browse files
fix(errors): change Unwrap method receiver to value type (#4232)
1 parent cf32d2d commit b38c59d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (msg *Error) IsType(flags ErrorType) bool {
9191
}
9292

9393
// Unwrap returns the wrapped error, to allow interoperability with errors.Is(), errors.As() and errors.Unwrap()
94-
func (msg *Error) Unwrap() error {
94+
func (msg Error) Unwrap() error {
9595
return msg.Err
9696
}
9797

errors_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,15 @@ func TestErrorUnwrap(t *testing.T) {
126126
require.ErrorIs(t, err, innerErr)
127127
var testErr TestErr
128128
require.ErrorAs(t, err, &testErr)
129+
130+
// Test non-pointer usage of gin.Error
131+
errNonPointer := Error{
132+
Err: innerErr,
133+
Type: ErrorTypeAny,
134+
}
135+
wrappedErr := fmt.Errorf("wrapped: %w", errNonPointer)
136+
// Check that 'errors.Is()' and 'errors.As()' behave as expected for non-pointer usage
137+
require.ErrorIs(t, wrappedErr, innerErr)
138+
var testErrNonPointer TestErr
139+
require.ErrorAs(t, wrappedErr, &testErrNonPointer)
129140
}

0 commit comments

Comments
 (0)