oerrs
is a package for Go that builds on top of golang.org/x/xerrors
.
Adds an ErrorList with optional stack traces.
Install using go get go.oneofone.dev/oerrs
.
Package documentation: https://pkg.go.dev/go.oneofone.dev/oerrs
- Passes through most
golang.org/x/xerrors
functions and interfaces to make life easier. - A complete drop-in replacement for
xerrors
- A complete drop-in replacement for
errgroup
ErrorList
handles multiple errors in a sane way.ErrorList
can optionally be toggled to enable thread safety.Try/Catch
needs doc.- All errors can support be toggled to support JSON output.
oerrs
was made to make error handling easier
var errs oerrs.ErrorList
errs.PushIf(step1())
errs.PushIf(step2())
if errs.PushIf(step3()) {
// do something
}
return errs.Err()
oerrs.ErrorList
implements error
if err := something(); err != nil {
if el, ok := err.(*oerrs.ErrorList); ok {
// Use merr.Errors
}
// or
var el *oerrs.ErrorList
if errors.As(err, &el) {
// use el.Errors
}
}
// try / catch
func doStuff() (res Response, err error) {
defer oerrs.Catch(&err, nil)
a := Try1(someFunThatReturnValAndErr())
// do something with a
b := Try1(someOtherFunc(a))
return a + b, nil
}
The code of errgroup is mostly copied from golang.org/x/sync
for personal convience, all rights reserved to go devs.
MIT