Join returns an error that wraps the given errors. Any nil error values are discarded. Join returns nil if errs contains no non-nil values. The error formats as the concatenation of the strings obtained by calling the Error method of each element of errs, with a newline between each string.
(errs ...error)
| 30 | // by calling the Error method of each element of errs, with a newline |
| 31 | // between each string. |
| 32 | func Join(errs ...error) error { |
| 33 | n := 0 |
| 34 | for _, err := range errs { |
| 35 | if err != nil { |
| 36 | n++ |
| 37 | } |
| 38 | } |
| 39 | if n == 0 { |
| 40 | return nil |
| 41 | } |
| 42 | e := &joinError{ |
| 43 | errs: make([]error, 0, n), |
| 44 | } |
| 45 | for _, err := range errs { |
| 46 | if err != nil { |
| 47 | e.errs = append(e.errs, err) |
| 48 | } |
| 49 | } |
| 50 | return e |
| 51 | } |
| 52 | |
| 53 | type joinError struct { |
| 54 | errs []error |
no outgoing calls
searching dependent graphs…