Combine one or more Go errors together
Go to file
Prashant Varanasi 8deb4d8f84 Avoid allocating a new slice on every Append (#9)
Currently, appending a non-nil error to a multierror always copies the underlying slice, since there may be multiple goroutines appending to the same multierr,
```go
merr := multierr.Append(errors.New("initial"), errors.New("multierr"))
go func() {
  err1 = multierr.Append(merr, errors.New("1"))
  [..]
}()
go func() {
  err2 = multierr.Append(merr, errors.New("2"))
  [..]
}()
```

However, the common use case is a standard for loop:
```go
var merr error
for _, v := range values {
  merr = multierr.Append(merr, processValue(v))
}
return merr
```

Since there is only a single resulting slice, we don't need to create a full copy on every `Append`. Instead, we track whether we have modified the underlying slice from `Append` already using an atomic boolean, and only create a copy if the underlying slice has been modified.
2017-04-10 15:02:29 -07:00
scripts Set up Travis CI (#2) 2017-03-22 17:54:47 -07:00
.gitignore Initial import (#1) 2017-03-22 17:05:00 -07:00
.travis.yml Set up Travis CI (#2) 2017-03-22 17:54:47 -07:00
CHANGELOG.md Preparing release v0.1.0 2017-03-31 17:20:13 -07:00
LICENSE.txt Initial import (#1) 2017-03-22 17:05:00 -07:00
Makefile Lint fixes (#4) 2017-03-22 18:16:12 -07:00
README.md Minimal readme (#3) 2017-03-22 17:54:35 -07:00
benchmarks_test.go Add benchmarks for different error cases (#7) 2017-03-27 11:13:53 -07:00
error.go Avoid allocating a new slice on every Append (#9) 2017-04-10 15:02:29 -07:00
error_test.go Avoid allocating a new slice on every Append (#9) 2017-04-10 15:02:29 -07:00
glide.lock Avoid allocating a new slice on every Append (#9) 2017-04-10 15:02:29 -07:00
glide.yaml Avoid allocating a new slice on every Append (#9) 2017-04-10 15:02:29 -07:00

README.md

multierr GoDoc Build Status Coverage Status

multierr allows combining one or more Go errors together.

Installation

go get -u go.uber.org/multierr

Status

Beta


Released under the MIT License.