I've run into an issue recently where I've had to move some code from returning a static error to wrapping that error, and noticed that there's not a builtin way to compare errors using the errors.Is function. Would it be possible to add an ErrorIs (or similarly named) Checker implementation that uses errors.Is to assert error similarity?
I can't continue to use ErrorMatches in this case because it doesn't capture the correct meaning of my error check. I want to know that I'm returning a specific kind of error even if it's wrapped or the message is modified.
eg:
// Previously
return package.StaticErrorValue
// Now
return fmt.Errorf("%w: %s", package.StaticErrorValue, reason)
// Tests:
c.Assert(err, ErrorIs, package.StaticErrorValue)
This is coming from go-git/go-git#1097 and https://github.com/go-git/go-git/blob/dcf0639a168c441de6753c6644322e6b619499ae/plumbing/transport/http/common.go#L414-L441 for some context.
I've run into an issue recently where I've had to move some code from returning a static error to wrapping that error, and noticed that there's not a builtin way to compare errors using the
errors.Isfunction. Would it be possible to add anErrorIs(or similarly named)Checkerimplementation that useserrors.Isto assert error similarity?I can't continue to use
ErrorMatchesin this case because it doesn't capture the correct meaning of my error check. I want to know that I'm returning a specific kind of error even if it's wrapped or the message is modified.eg:
This is coming from go-git/go-git#1097 and https://github.com/go-git/go-git/blob/dcf0639a168c441de6753c6644322e6b619499ae/plumbing/transport/http/common.go#L414-L441 for some context.