Documentation ¶
Index ¶
- Variables
- func Append(err error, errs ...error) error
- func Inspect(err error) []error
- func ListFormatterFunc(errs []error) string
- func Merge(err error, errs ...error) error
- func Titled(err error, title string) error
- func Titledf(err error, format string, args ...interface{}) error
- type Error
- type FormatterFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultFormatter = ListFormatterFunc
DefaultFormatter specifies the error formatter that is used for errors that don't have a dedicated formatter function specified.
Functions ¶
func Append ¶
Append combines all errors into a single multi-error. Any nil-error will be ignored. Returns nil if there are no errors. A returned error will always be of type *Error.
If err is a multierr.Error, it will be reused (the title and error-slice are kept). Otherwise a new multierr.Error is created.
func Inspect ¶
Inspect returns all embedded sub-errors or nil if there are no errors. If err is not a multi-error, an error-slice with one element is returned.
func ListFormatterFunc ¶
ListFormatterFunc puts each sub-error in a new, indented line. The errors are titled with a generic "n errors occurred".
func Merge ¶
Merge combines all errors into a single multi-error. Any nil-error will be ignored. Returns nil if there are no errors. A returned error will always be of type *Error.
If any errs is a multierr.Error, it will be flattened.
If err is a multierr.Error, it will be reused (the title and error-slice are kept). Otherwise, a new multierr.Error is created.
func Titled ¶
Titled sets the error formatter to a TitledListFormatter. The given title is used when calling Error.Error().
If the error is not a multierr.Error, it will be converted. Returns nil if the error is nil. Otherwise, the result is always an *Error. This is equivalent of setting Error.Formatter directly.
Types ¶
type Error ¶
type Error struct { Formatter FormatterFunc Errors []error }
Error is an error type to track multiple errors. This is used to accumulate errors in cases and return them as a single "error".
func (*Error) Error ¶
Error converts the error into a human readable string. Uses the error-specific formatter or, if none is specified, the DefaultFormatter.
func (*Error) Unwrap ¶
Unwrap returns the first error in Error or nil if there are no errors. By repeatedly calling Unwrap on the return value (until nil is returned), all (recursively) contained sub-errors can be obtained. Errors are unwrapped depth-first. This implements errors.Is/errors.As/errors.Unwrap methods from the standard library. Appending new errors while unwrapping has no effect (shallow copy).
type FormatterFunc ¶
FormatterFunc is called by Error.Error() to convert multi-errors into a human readable strings.
func TitledListFormatter ¶
func TitledListFormatter(title string) FormatterFunc
TitledListFormatter returns a formatter func that puts each sub-error in a new, indented line. The errors are titled with the given text.