Documentation
¶
Overview ¶
Package merrors implements multi error implementation that chains errors on the same level. Supports errors.As and errors.Is functions.
Example 1:
return merrors.New(err1, err2).Err()
Example 2:
merr := merrors.New(err1)
merr.Add(err2, errOrNil3)
for _, err := range errs {
merr.Add(err)
}
return merr.Err()
Example 3:
func CloseAll(closers []io.Closer) error {
errs := merrors.New()
for _ , c := range closers {
errs.Add(c.Close())
}
return errs.Err()
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error interface {
error
// Errors returns underlying errors.
Errors() []error
// As finds the first error in multiError slice of error chains that matches target, and if so, sets
// target to that error value and returns true. Otherwise, it returns false.
//
// An error matches target if the error's concrete value is assignable to the value
// pointed to by target, or if the error has a method As(interface{}) bool such that
// As(target) returns true. In the latter case, the As method is responsible for
// setting target.
As(target interface{}) bool
// Is returns true if any error in multiError's slice of error chains matches the given target or
// if the target is of multiError type.
//
// An error is considered to match a target if it is equal to that target or if
// it implements a method Is(error) bool such that Is(target) returns true.
Is(target error) bool
// Count returns the number of multi error' errors that match the given target.
// Matching is defined as in Is method.
Count(target error) int
}
Error is extended error interface that allows to use returned read-only multi error in more advanced ways.
type NilOrMultiError ¶
type NilOrMultiError struct {
// contains filtered or unexported fields
}
NilOrMultiError type allows combining multiple errors into one.
func New ¶
func New(errs ...error) *NilOrMultiError
New returns NilOrMultiError with provided errors added if not nil.
func (*NilOrMultiError) Add ¶
func (e *NilOrMultiError) Add(errs ...error)
Add adds single or many errors to the error list. Each error is added only if not nil. If the error is a multiError type, the errors inside multiError are added to the main NilOrMultiError.
func (NilOrMultiError) Err ¶
func (e NilOrMultiError) Err() Error
Err returns the error list as an Error (also implements error) or nil if it is empty.