errors

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Is reports whether any error in err's tree matches target.
	//
	// The tree consists of err itself, followed by the errors obtained by repeatedly
	// calling Unwrap. When err wraps multiple errors, Is examines err followed by a
	// depth-first traversal of its children.
	//
	// 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 == fs.ErrExist }
	//
	// then Is(MyError{}, fs.ErrExist) returns true. See syscall.Errno.Is for
	// an example in the standard library. An Is method should only shallowly
	// compare err and the target and not call Unwrap on either.
	Is = errors.Is

	// 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.
	//
	// The tree consists of err itself, followed by the errors obtained by repeatedly
	// calling Unwrap. When err wraps multiple errors, As examines err followed by a
	// depth-first traversal of its children.
	//
	// 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.
	As = errors.As
)

Functions

func New

func New(msg string, args ...any) *baseError

New creates a new error with stacktrace

func NewSentinel added in v0.1.0

func NewSentinel(typeStr, msg string) *baseError

NewSentinel error, without a stacktrace or metadata assigned to it.

func NewWithType added in v0.0.2

func NewWithType(msg, typeStr string, args ...any) *baseError

NewWithType creates a new error with stacktrace and a custom type string returned by its Type() method

func RecoverPanic

func RecoverPanic(r interface{}, errPtr *error)

func SentinelWithStack added in v0.0.2

func SentinelWithStack(err error) *baseError

SentinelWithStack wraps the given sentinel error. It adds a stacktrace and propagates both the type and message.

func W added in v0.0.2

func W(err error) *baseError

W wraps an error in a new error with stacktrace and propagating the metadata.

func Wrap

func Wrap(err error, msg string, args ...any) *baseError

Wrap wraps the given error in a new Error with the given message, having a stacktrace and propagating metadata.

func WrapAsSentinel added in v0.1.2

func WrapAsSentinel(err error, typeStr, msg string) *baseError

Wrap a sentinel error as another sentinel error, without a stacktrace or metadata assigned to it.

func WrapWithType added in v0.0.2

func WrapWithType(err error, msg, typeStr string, args ...any) *baseError

Wrap wraps the given error in a new error with stack trace and a custom type string returned by its Type() method

Types

type Frame added in v0.0.2

type Frame struct {
	runtime.Frame
}

func (Frame) FuncName added in v0.0.2

func (f Frame) FuncName() string

func (Frame) Package added in v0.0.2

func (f Frame) Package() string

type Metadata added in v0.1.0

type Metadata map[string]interface{}

func GetMetadata added in v0.1.0

func GetMetadata(err error) *Metadata

type StackTrace

type StackTrace []Frame

type WrappedError added in v0.1.0

type WrappedError interface {
	error
	Unwrap() error
}

Jump to

Keyboard shortcuts

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