# README
Errors
A replacement for errors
and pkg/errors
. Supports error wrapping, inspection and multi errors.
Issues
Implementation
- doc/design contains some survey and design choices we made
Wrap
checks if this is already aWrappedErr
, if not, it attaches stackMultiErr
keep a slice of errors, the thread safe version use mutex and returns copy of slice whenErrors
is called
References and Alternatives
- golang/xerrors Official error wrapping
fmt.Errorf("oh my %w", err)
- rotisserie/eris
- go-rewrap-errors Conver pkg/errors to standard library wrapping
# Packages
Package errortype defines helper for inspect common error types generated in standard library, so you don't need to import tons of packages in your file for sentinel error and custom error type.
No description provided by the author
# Functions
As walks the error chain and save the matched error in target.
Cause returns root cause of the error (if any), it stops at the last error that does not implement causer interface.
Errorf is New with fmt.Sprintf.
GetType walks the error chain and match by type using reflect, It returns the matched error and match result.
GetTypeOf requires user to call reflect.TypeOf(exampleErr) as target type.
Ignore swallow the error, you should NOT use it unless you know what you are doing (make the lint tool happy) It is inspired by dgraph x/error.go.
Ignore2 allow you to ignore return value and error, it is useful for io.Writer like functions It is also inspired by dgraph x/error.go.
Is walks the error chain and do direct compare.
IsType walks the error chain and match by type using reflect.
IsTypeOf requires user to call reflect.TypeOf(exampleErr).String() as the type string.
New creates a freshError with stack trace.
NewMultiErr returns a non thread safe implementation.
NewMultiErrSafe returns a thread safe implementation which protects the underlying slice using mutex.
No description provided by the author
Unwrap returns the first underlying error.
Walk traverse error chain and error list, it stops when there is no underlying error or the WalkFunc decides to stop.
Wrap creates a wrappedError with stack and set its cause to err.
Wrapf is Wrap with fmt.Sprintf.
# Constants
ErrCauseSep is the separator used when returning a error with causal chain as single line message.
MultiErrSep is the separator used when returning a slice of errors as single line message.
# Interfaces
ErrorList is a list of errors that do not fit into the Wrapper model because they are at same level and don't have direct causal relationships.
Message return the top level error message without traverse the error chain i.e.
MultiErr is a slice of Error.
No description provided by the author
Tracer is error with stack trace.
Wrapper is based on go 2 proposal, it only has an Unwrap method to returns the underlying error.
# Type aliases
WalkFunc accepts an error and based on its inspection logic it can tell Walk if it should stop walking the error chain or error list.