Documentation
¶
Index ¶
- func As(err error, target any) bool
- func Cause(err error) error
- func Is(err, reference error) bool
- func New(text string) error
- func Unwrap(err error) error
- func UnwrapAll(err error) error
- func UnwrapOnce(err error) (cause error)
- func With(back, front error) error
- func WithStack(err error) error
- func WithStackDepth(err error, depth int) error
- func Wrap(err error, msg string) error
- func WrapWithFields(err error, fields Fields) error
- func WrapWithFieldsAndDepth(err error, fields Fields, depth int) error
- func Wrapf(err error, format string, args ...interface{}) error
- type Aser
- type Fields
- type Iser
- type Stack
- type StackTrace
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As finds the first error in err's chain that matches the type to which target points, and if so, sets the target to its value and returns true. An error matches a type if it is assignable to the target type, or if it has a method As(any) bool such that As(target) returns true. As will panic if target is not a non-nil pointer to a type which implements error or is of interface type.
The As method should set the target to its value and return true if err matches the type to which target points.
Note: this implementation differs from that of xerrors as follows: - it also supports recursing through causes with Cause(). - if it detects an API use error, its panic object is a valid error.
func Is ¶
Is determines whether one of the causes of the given error or any of its causes is equivalent to some reference error.
As in the Go standard library, an error is considered to match a reference error if it is equal to that target or if it implements a method Is(error) bool such that Is(reference) returns true.
Note: the inverse is not true - making an Is(reference) method return false does not imply that errors.Is() also returns false. Errors can be equal because their network equality marker is the same. To force errors to appear different to Is(), use errors.Mark().
Note: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to Is(). Is determines whether one of the causes of the given error or any of its causes is equivalent to some reference error.
As in the Go standard library, an error is considered to match a reference error if it is equal to that target or if it implements a method Is(error) bool such that Is(reference) returns true.
Note: the inverse is not true - making an Is(reference) method return false does not imply that errors.Is() also returns false. Errors can be equal because their network equality marker is the same. To force errors to appear different to Is(), use errors.Mark().
Note: if any of the error types has been migrated from a previous package location or a different type, ensure that RegisterTypeMigration() was called prior to Is().
func New ¶
New returns an error that formats as the given text. Each call to New returns a distinct error value even if the text is identical.
func UnwrapAll ¶
UnwrapAll accesses the root cause object of the error. If the error has no cause (leaf error), it is returned directly.
func UnwrapOnce ¶
UnwrapOnce accesses the direct cause of the error if any, otherwise returns nil.
It supports both errors implementing causer (`Cause()` method, from github.com/pkg/errors) and `Wrapper` (`Unwrap()` method, from the Go 2 error proposal).
func With ¶
With returns an error that represents front wrapped over back. If back is nil, the returned error is nil.
Calling Unwrap in a loop on this error will iteratively unwrap the front error first, until it runs out of wrapped errors, and then return the back error. This is also the order that Is and As will read the wrapped errors.
The returned error's message will be the concatenation of the two error strings.
func WithStackDepth ¶
WithStackDepth annotates err with a wrapper trace starting from the given call depth. The value zero identifies the caller of WithStackDepth itself. See the documentation of WithStack() for more details.
func WrapWithFields ¶
WrapWithFields adds fields to an existing error.
func WrapWithFieldsAndDepth ¶
Types ¶
type Stack ¶
type Stack []uintptr
Stack represents a Stack of program counters. This mirrors the (non-exported) type of the same name in github.com/pkg/errors.
func Callers ¶
Callers mirrors the code in github.com/pkg/errors, but makes the skip depth customizable.
func ElideSharedStackSuffix ¶
ElideSharedStackSuffix removes the suffix of newStack that's already present in prevStack. The function returns true if some entries were elided. type StackTrace []Frame -> type StackTrace runtime.Frames callers []uintptr
func (*Stack) Format ¶
Format mirrors the code in github.com/pkg/errors. https://github.com/pkg/errors/blob/master/stack.go#L142
func (*Stack) StackTrace ¶
func (s *Stack) StackTrace() *StackTrace
StackTrace mirrors the code in github.com/pkg/errors.
type StackTrace ¶
StackTrace is Stack of Frames from innermost (newest) to outermost (oldest).
func (*StackTrace) Next ¶
func (st *StackTrace) Next() (_ runtime.Frame, more bool)
Next returns the next frame in the wrapper trace, and a boolean indicating whether there are more after it.
func (*StackTrace) String ¶
func (st *StackTrace) String() string