mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-22 12:19:16 +08:00
fix(errors): change Unwrap method receiver to value type (#4232)
This commit is contained in:
parent
cf32d2dcf8
commit
b38c59de7f
@ -91,7 +91,7 @@ func (msg *Error) IsType(flags ErrorType) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unwrap returns the wrapped error, to allow interoperability with errors.Is(), errors.As() and errors.Unwrap()
|
// Unwrap returns the wrapped error, to allow interoperability with errors.Is(), errors.As() and errors.Unwrap()
|
||||||
func (msg *Error) Unwrap() error {
|
func (msg Error) Unwrap() error {
|
||||||
return msg.Err
|
return msg.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,4 +126,15 @@ func TestErrorUnwrap(t *testing.T) {
|
|||||||
require.ErrorIs(t, err, innerErr)
|
require.ErrorIs(t, err, innerErr)
|
||||||
var testErr TestErr
|
var testErr TestErr
|
||||||
require.ErrorAs(t, err, &testErr)
|
require.ErrorAs(t, err, &testErr)
|
||||||
|
|
||||||
|
// Test non-pointer usage of gin.Error
|
||||||
|
errNonPointer := Error{
|
||||||
|
Err: innerErr,
|
||||||
|
Type: ErrorTypeAny,
|
||||||
|
}
|
||||||
|
wrappedErr := fmt.Errorf("wrapped: %w", errNonPointer)
|
||||||
|
// Check that 'errors.Is()' and 'errors.As()' behave as expected for non-pointer usage
|
||||||
|
require.ErrorIs(t, wrappedErr, innerErr)
|
||||||
|
var testErrNonPointer TestErr
|
||||||
|
require.ErrorAs(t, wrappedErr, &testErrNonPointer)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user