4 ms·
Yup, my solution as well. As well as a couple other common libraries (eg: https://github.com/pkg/errors https://github.com/pkg/errors) The only downside to thi
by notheguyouthink 10y ago
Yup, my solution as well. As well as a couple other common libraries (eg: https://github.com/pkg/errors https://github.com/pkg/errors)
The only downside to this is you can no longer treat errors as values. Eg, you can't do:
err := Func()
if err == ErrBadThing {
// do stuff
}
So you have to implement some type of `Cause()` method. In my lib, i have `errors.Cause()` which returns the root error, as well as a shorthand func `errors.Equals(err, ErrBadThing`)`