Can't us errors.As to identify an custom error which has been wrapped multiple times
kjico opened this issue · 2 comments
kjico commented
When using a custom error and then wrapping that error with eris.Wrap it's not possible to use errors.As to identify if error is made of target, even if Unwrap is implemented.
package main
import (
"errors"
"fmt"
"github.com/rotisserie/eris"
)
type AnError struct {
Msg string
Err error
}
func (ae AnError) Error() string {
return ae.Msg
}
func (ae AnError) Unwrap() error {
return ae.Err
}
func main() {
aerror := AnError{Msg: "invalid", Err: eris.New("eris test error")}
berr := eris.Wrap(aerror, "the error")
switch {
case errors.As(berr, &AnError{}):
fmt.Println("anerror")
}
}
I expected this code should print "anerror", if I instead wrap the error with fmt.Errorf and %w, it works as expected.
morningvera commented
Thanks for the bug report! We've been planning to add our own version of As
and we'll look into it soon.
morningvera commented
hey @kjico, we merged a fix for this last week, and we're working on adding our own version of As this week. thanks for the feedback!