xerrors

package
v0.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

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 Errorf

func Errorf(format string, a ...interface{}) error

func Is

func Is(err, target error) bool

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 New

func New(text string) error

func SkipErrorf

func SkipErrorf(skip int, format string, a ...interface{}) error

func Unwrap

func Unwrap(err error) error

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.

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

func NewSentinel(text string) *Sentinel

NewSentinel acts as New but does not add stack frame

func (*Sentinel) WithFrame

func (s *Sentinel) WithFrame() error

WithFrame adds stack frame to sentinel error (DEPRECATED)

func (*Sentinel) WithStackTrace

func (s *Sentinel) WithStackTrace() error

func (*Sentinel) Wrap

func (s *Sentinel) Wrap(err error) error

Wrap error with this sentinel error. Adds stack frame.

type Wrapper

type Wrapper interface {
	// Unwrap returns the next error in the error chain.
	// If there is no next error, Unwrap returns nil.
	Unwrap() error
}

Wrapper provides context around another error.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL