Documentation
¶
Overview ¶
Package multierror provides a type for composite errors.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a (possibly composite) error that represents the errors in the provided list.
Any nil errors in the list are removed, and any MultipleErrors instances in the list are replaced with their inlined contents (recursively). If the resulting list is empty, error(nil) is returned. If the resulting list contains a single error, that error is returned directly. Otherwise, an instance of MultipleErrors is returned.
Types ¶
type MultipleErrors ¶
type MultipleErrors []error
MultipleErrors is an implementation of error that is made of other errors. This is useful in situations where it makes sense to collect and present as many errors as possible, e.g. in validating user input, rather than to stop at the first error and report it.
Example (Empty) ¶
fmt.Printf("%T: %[1]v\n", Of())
Output: <nil>: <nil>
Example (Many) ¶
fmt.Printf("%T: %[1]v\n", Of(errorA, errorB, errorC))
Output: multierror.MultipleErrors: encountered multiple errors: ... A ... B ... C
Example (Nested) ¶
inner := MultipleErrors{errorA, nil} mid := MultipleErrors{inner, nil, errorB} outer := Of(mid, errorC) fmt.Printf("%T: %[1]v\n", Of(errorA, errorB, errorC)) fmt.Printf("Len=%d\n", len(outer.(MultipleErrors)))
Output: multierror.MultipleErrors: encountered multiple errors: ... A ... B ... C Len=3
Example (Nil) ¶
fmt.Printf("%T: %[1]v\n", Of(nil, nil, nil))
Output: <nil>: <nil>
Example (One) ¶
fmt.Printf("%T: %[1]v\n", Of(errorA))
Output: multierror.exampleError: A
func (MultipleErrors) Error ¶
func (e MultipleErrors) Error() string