Documentation ¶
Overview ¶
Package errors contains helper functions for wrapping errors with stack traces, stack output, and panic recovery.
Index ¶
- func As(err error, target any) bool
- func ContainsStackTrace(err error) bool
- func ErrorStack(err error) string
- func Errorf(format string, vals ...any) error
- func Is(err, target error) bool
- func IsContextCanceled(err error) bool
- func IsError(actual error, expected error) bool
- func Join(errs ...error) error
- func New(val any) error
- func Recover(onPanic func(cause error))
- func Unwrap(err error) error
- func UnwrapErrors(err error) []error
- func UnwrapMultiErrors(err error) []error
- type MultiError
- func (errs *MultiError) Append(appendErrs ...error) *MultiError
- func (errs *MultiError) Error() string
- func (errs *MultiError) ErrorOrNil() error
- func (errs *MultiError) Len() int
- func (errs *MultiError) Less(i, j int) bool
- func (errs *MultiError) Swap(i, j int)
- func (errs *MultiError) Unwrap() []error
- func (errs *MultiError) WrappedErrors() []error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As finds the first error in err's tree that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false.
func ContainsStackTrace ¶
ContainsStackTrace returns true if the given error contain the stack trace. Useful to avoid creating a nested stack trace.
func Errorf ¶
Errorf creates a new error with the given format and values. It can be used as a drop-in replacement for fmt.Errorf() to provide descriptive errors in return values. If none of the given values contains a stack trace, it will be created.
func IsContextCanceled ¶
IsContextCanceled returns `true` if error has occurred by event `context.Canceled` which is not really an error.
func IsError ¶
IsError returns true if actual is the same type of error as expected. This method unwraps the given error objects (if they are wrapped in objects with a stacktrace) and then does a simple equality check on them.
func New ¶
New creates a new instance of Error. If the given value does not contain a stack trace, it will be created.
func Recover ¶
func Recover(onPanic func(cause error))
Recover tries to recover from panics, and if it succeeds, calls the given onPanic function with an error that explains the cause of the panic. This function should only be called from a defer statement.
func Unwrap ¶
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.
func UnwrapErrors ¶
UnwrapErrors unwraps all nested multierrors, and errors that were wrapped with `fmt.Errorf("%w", err)`.
func UnwrapMultiErrors ¶
UnwrapMultiErrors unwraps all nested multierrors into error slice.
Types ¶
type MultiError ¶
type MultiError struct {
// contains filtered or unexported fields
}
MultiError is an error type to track multiple errors.
func (*MultiError) Append ¶
func (errs *MultiError) Append(appendErrs ...error) *MultiError
Append is a helper function that will append more errors onto an Multierror in order to create a larger errs-error.
func (*MultiError) Error ¶
func (errs *MultiError) Error() string
Error implements the error interface.
func (*MultiError) ErrorOrNil ¶
func (errs *MultiError) ErrorOrNil() error
ErrorOrNil returns an error interface if this Error represents a list of errors, or returns nil if the list of errors is empty.
func (*MultiError) Len ¶
func (errs *MultiError) Len() int
Len implements sort.Interface function for length.
func (*MultiError) Less ¶
func (errs *MultiError) Less(i, j int) bool
Less implements sort.Interface function for determining order.
func (*MultiError) Swap ¶
func (errs *MultiError) Swap(i, j int)
Swap implements sort.Interface function for swapping elements.
func (*MultiError) Unwrap ¶
func (errs *MultiError) Unwrap() []error
func (*MultiError) WrappedErrors ¶
func (errs *MultiError) WrappedErrors() []error
WrappedErrors returns the error slice that this Error is wrapping.