11# go-multierror
22
3- [ ![ Build Status] ( http://img.shields.io/travis/hashicorp/go-multierror.svg?style=flat-square )] [ travis ]
4- [ ![ Go Documentation] ( http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square )] [ godocs ]
5-
6- [ travis ] : https://travis-ci.org/hashicorp/go-multierror
7- [ godocs ] : https://godoc.org/github.com/hashicorp/go-multierror
8-
93` go-multierror ` is a package for Go that provides a mechanism for
104representing a list of ` error ` values as a single ` error ` .
115
@@ -14,16 +8,12 @@ be a list of errors. If the caller knows this, they can unwrap the
148list and access the errors. If the caller doesn't know, the error
159formats to a nice human-readable format.
1610
17- ` go-multierror ` implements the
18- [ errwrap] ( https://github.com/hashicorp/errwrap ) interface so that it can
19- be used with that library, as well.
11+ This is a fork of the hashicorp ` go-multierror ` library. In this
12+ fork, nil error values are handled transparently.
2013
2114## Installation and Docs
2215
23- Install using ` go get github.com/hashicorp/go-multierror ` .
24-
25- Full documentation is available at
26- http://godoc.org/github.com/hashicorp/go-multierror
16+ Install using ` go get github.com/mspiegel/go-multierror ` .
2717
2818## Usage
2919
@@ -38,14 +28,12 @@ if the first argument is nil, a `multierror.Error`, or any other `error`,
3828the function behaves as you would expect.
3929
4030``` go
41- var result error
31+ var err , result error
4232
43- if err := step1 (); err != nil {
44- result = multierror.Append (result, err)
45- }
46- if err := step2 (); err != nil {
47- result = multierror.Append (result, err)
48- }
33+ err = step1 ()
34+ result = multierror.Append (result, err)
35+ err = step2 ()
36+ result = multierror.Append (result, err)
4937
5038return result
5139```
@@ -79,19 +67,4 @@ if err := something(); err != nil {
7967 // Use merr.Errors
8068 }
8169}
82- ```
83-
84- ** Returning a multierror only if there are errors**
85-
86- If you build a ` multierror.Error ` , you can use the ` ErrorOrNil ` function
87- to return an ` error ` implementation only if there are errors to return:
88-
89- ``` go
90- var result *multierror.Error
91-
92- // ... accumulate errors here
93-
94- // Return the `error` only if errors were added to the multierror, otherwise
95- // return nil since there are no errors.
96- return result.ErrorOrNil ()
97- ```
70+ ```
0 commit comments