Go wrapper for multiple errors
To start using errors, install Go and run go get:
$ go get github.com/rqme/errorsUsing errors is as simple as
import . "github.com/rqme/errors"
...
func main() {
errs := new(Errors)
...
if err := os.Create("foo.txt"); err != nil {
errs.Add(err)
}
...
err := fmt.Errorf("Something didn't work, %s", "Jack")
errs.Add(Err)
...
log.Fatal(errs.Err())
}The errors package name conflicts with the standard package errors so you can use the . prefix to hide it.
Note: errors is not concurrency safe. This can be done with the sync package
import (
. "github.com/rqme/errors"
"sync"
)
...
func main() {
errs = new(Errors)
m := new(sync.Mutex)
addErr := func(err error) {
m.Lock()
errs.Add(err)
m.Unlock()
}
...
go func() {
err := ...
addErr(Err)
}
...
log.Fatal(errs.Err())
}
...