Documentation ¶
Overview ¶
package xerrors is a drop in replacement for errors and golang.org/x/xerrors packages and functionally for github.com/pkg/errors.
Index ¶
- func As(err error, target interface{}) bool
- func DefaultStackTraceMode()
- func DisableStackTraces()
- func EnableFrames()
- func EnableStackThenFrames()
- func EnableStackThenNothing()
- func EnableStacks()
- func Errorf(format string, a ...interface{}) error
- func Is(err, target error) bool
- func MaxStackFrames128()
- func MaxStackFrames16()
- func MaxStackFrames32()
- func MaxStackFrames64()
- func New(text string) error
- func SkipErrorf(skip int, format string, a ...interface{}) error
- func Unwrap(err error) error
- type ErrorStackTrace
- type Sentinel
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
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.
An error type might provide an As method so it can be treated as if it were a different error type.
As panics if target is not a non-nil pointer to either a type that implements error, or to any interface type.
func DefaultStackTraceMode ¶
func DefaultStackTraceMode()
func DisableStackTraces ¶
func DisableStackTraces()
func EnableFrames ¶
func EnableFrames()
func EnableStackThenFrames ¶
func EnableStackThenFrames()
func EnableStackThenNothing ¶
func EnableStackThenNothing()
func EnableStacks ¶
func EnableStacks()
func Is ¶
Is reports whether any error in err's chain matches target.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
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.
An error type might provide an Is method so it can be treated as equivalent to an existing error. For example, if MyError defines
func (m MyError) Is(target error) bool { return target == os.ErrExist }
then Is(MyError{}, os.ErrExist) returns true. See syscall.Errno.Is for an example in the standard library.
func MaxStackFrames128 ¶
func MaxStackFrames128()
func MaxStackFrames16 ¶
func MaxStackFrames16()
func MaxStackFrames32 ¶
func MaxStackFrames32()
func MaxStackFrames64 ¶
func MaxStackFrames64()
func SkipErrorf ¶
Types ¶
type ErrorStackTrace ¶
type ErrorStackTrace interface {
StackTrace() *xruntime.StackTrace
}
func NextStackTrace ¶
func NextStackTrace(st ErrorStackTrace) ErrorStackTrace
NextStackTracer returns next error with stack trace. Guarantees that returned value has valid StackTrace object (but not that there are any frames).
func StackTraceOfCause ¶
func StackTraceOfCause(err error) ErrorStackTrace
StackTraceOfCause returns first stacktrace that was added to error chain (closest to the root error). Guarantees that returned value has valid StackTrace object (but not that there are any frames).
func StackTraceOfEffect ¶
func StackTraceOfEffect(err error) ErrorStackTrace
StackTraceOfEffect returns last stacktrace that was added to error chain (furthest from the root error). Guarantees that returned value has valid StackTrace object (but not that there are any frames).
type Sentinel ¶
type Sentinel struct {
// contains filtered or unexported fields
}
Sentinel error
func NewSentinel ¶
NewSentinel acts as New but does not add stack frame