go-errors / errors

errors with stacktraces for go
https://godoc.org/github.com/go-errors/errors
MIT License
921 stars 93 forks source link

Add Unwrap? #14

Closed matthijskooijman closed 4 years ago

matthijskooijman commented 7 years ago

Would it make sense to add an Unwrap() function to this library? I have a usecase where I need to check the type of the underlying error, which (AFAICS) Is() cannot do. I can access the Err field of an errors.Error, but that requires having a *Error instead of an error, which AFAIU isn't the intended way to return (wrapped) errors.

Such a function could simply look like:

func Unwrap(err error) error {
        switch e := err.(type) {
                case *errors.Error:
                        return e.Err
                default:
                        return err
        }
}
titouanfreville commented 4 years ago

I don't think this is still relevant with latest go version and fix of go-errors Is method in v1.1.0