-
-
Notifications
You must be signed in to change notification settings - Fork 34
Closed
Description
Hi! At first, thanks for this great package, really simplifies error building.
I've noticed some weird behavior when using errors.Is with oops errors.
Currently, oopsError.Is(oopsError) returns false for the same error instance, which is counter-intuitive. I would expect that any error should be considered to be "Is" itself, similar to how the standard errors package works.
Demonstration test case:
package main
import (
"errors"
"testing"
"github.com/samber/oops"
"github.com/stretchr/testify/assert"
)
var MyErr1 = errors.New("my custom error")
var MyOopsErr = oops.New("my oops error")
func TestErrIs(t *testing.T) {
// is fine
assert.ErrorIs(t, MyErr1, MyErr1, "Standard error should be Is itself")
// fails
identity := errors.Is(MyOopsErr, MyOopsErr)
assert.True(t, identity, "Oops error should be Is itself")
// also fails
oopsed, _ := oops.AsOops(MyOopsErr)
assert.True(t, oopsed.Is(MyOopsErr), "Converted Oops error should be Is itself")
// fails
assert.ErrorIs(t, MyOopsErr, MyOopsErr, "errors.Is should work with Oops errors")
}It's a bit inconvenient especially during tests, where testify/assert.ErrorIs is reporting a failure for oops errors.
Is this intentional behavior?
Metadata
Metadata
Assignees
Labels
No labels