1
1
# go-multierror
2
2
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
-
9
3
` go-multierror ` is a package for Go that provides a mechanism for
10
4
representing a list of ` error ` values as a single ` error ` .
11
5
6
+ This is a fork of the hashicorp ` go-multierror ` library. In this
7
+ fork, nil error values are handled transparently.
8
+
12
9
This allows a function in Go to return an ` error ` that might actually
13
10
be a list of errors. If the caller knows this, they can unwrap the
14
11
list and access the errors. If the caller doesn't know, the error
15
12
formats to a nice human-readable format.
16
13
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.
20
-
21
14
## Installation and Docs
22
15
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 ` .
27
17
28
18
## Usage
29
19
@@ -38,14 +28,12 @@ if the first argument is nil, a `multierror.Error`, or any other `error`,
38
28
the function behaves as you would expect.
39
29
40
30
``` go
41
- var result error
31
+ var err , result error
42
32
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)
49
37
50
38
return result
51
39
```
@@ -79,19 +67,4 @@ if err := something(); err != nil {
79
67
// Use merr.Errors
80
68
}
81
69
}
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