Open ggambetti opened 3 months ago
You can define your own custom checkers - they just need to satisfy the Checker
interface. We've done exactly what you're asking here:
https://github.com/juju/testing/blob/e8c2c6dee228df02bae64e27d1715fe62b682bb9/checkers/error.go
That's what I implemented in the linked PR around the time I filed this issue: https://github.com/go-git/go-git/pull/1100/files#diff-df7610266a25d996bedf7b6be25b5b08e69445cdeb262833ea9be5c3bf1fdc6f.
I'm of the opinion that errors.Is
is sufficiently fundamental to error handling in Go that it warrants inclusion into this library.
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 anErrorIs
(or similarly named)Checker
implementation that useserrors.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:
This is coming from https://github.com/go-git/go-git/issues/1097 and https://github.com/go-git/go-git/blob/dcf0639a168c441de6753c6644322e6b619499ae/plumbing/transport/http/common.go#L414-L441 for some context.