https://github.com/oneofone/oerrs
Yet another go package with an error list
https://github.com/oneofone/oerrs
Last synced: about 2 months ago
JSON representation
Yet another go package with an error list
- Host: GitHub
- URL: https://github.com/oneofone/oerrs
- Owner: OneOfOne
- License: mit
- Created: 2021-06-15T21:01:32.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-21T19:22:35.000Z (almost 3 years ago)
- Last Synced: 2025-01-21T05:25:04.493Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oerrs
[](https://pkg.go.dev/go.oneofone.dev/oerrs)

[godocs]: https://pkg.go.dev/go.oneofone.dev/oerrs
`oerrs` is a package for Go that builds on top of [`golang.org/x/xerrors`](https://golang.org/x/xerrors).
Adds an ErrorList with optional stack traces.
## Installation and Docs
Install using `go get go.oneofone.dev/oerrs`.
Package documentation:
### Requires go version 1.18 or newer
## Features
* Passes through most [`golang.org/x/xerrors`](https://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.
## Usage
`oerrs` was made to make error handling easier
## Examples
```go
var errs oerrs.ErrorList
errs.PushIf(step1())
errs.PushIf(step2())
if errs.PushIf(step3()) {
// do something
}
return errs.Err()
```
`oerrs.ErrorList` implements `error`
```go
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
}
}
```
```go
// 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
}
```
## License
The code of errgroup is mostly copied from [`golang.org/x/sync`](https://golang.org/x/sync) for personal convience, all rights reserved to go devs.
MIT