errors

package
v0.0.0-...-ed64d5f Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

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

func Collect

func Collect(cerr error, uerr ...error) error

Collect is used to collect multiple errors. `Unwrap` is noop and `Is(err, ErrMine) == true`. While `As(err, underlyingError)` do not work, you can still get underlying errors by `MError.Cause`.

func Errorf

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

func Is

func Is(err, target error) bool

func New

func New(text string) error

func Unwrap

func Unwrap(err error) error

func WithStack

func WithStack(err error) error

WithStack will wrapping an error with stacktrace, given a default stack depth.

func WithStackDepth

func WithStackDepth(err error, depth int) error

WithStackDepth is like WithStack, but can specify stack depth.

func Wrap

func Wrap(cerr error, uerr error) error

Wrap is used to wrapping unknown errors. A typical example is that: 1. have a function `ReadMyConfig()` 2. it got errors returned from external libraries 3. you want to wrap these errors, expect `Unwrap(err) == ErrReadMyConfig && Is(err, ErrReadMyConfig) && Is(err, ErrExternalErrors)`. 4. then you are finding `err := Wrap(ErrReadMyConfig, ErrExternalErrors)` Note that wrap nil error will get nil error.

func Wrapf

func Wrapf(cerr error, msg string, args ...interface{}) error

Wrapf is like Wrap, with the underlying error being the result of `fmt.Errorf()`

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a simple error wrapper with stacktrace.

func (*Error) As

func (e *Error) As(target interface{}) bool

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(st fmt.State, verb rune)

Format implements `fmt.Formatter`. %+v/%v will contain stacktrace compared to %s.

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type MError

type MError struct {
	// contains filtered or unexported fields
}

func (*MError) Cause

func (e *MError) Cause() []error

func (*MError) Error

func (e *MError) Error() string

func (*MError) Format

func (e *MError) Format(st fmt.State, verb rune)

func (*MError) Is

func (e *MError) Is(s error) bool

type WError

type WError struct {
	// contains filtered or unexported fields
}

func (*WError) Error

func (e *WError) Error() string

func (*WError) Format

func (e *WError) Format(st fmt.State, verb rune)

func (*WError) Is

func (e *WError) Is(s error) bool

func (*WError) Unwrap

func (e *WError) Unwrap() error

type Warning

type Warning struct {
	Err error
}

func (*Warning) Error

func (e *Warning) Error() string

func (*Warning) Is

func (e *Warning) Is(target error) bool

func (*Warning) Unwrap

func (e *Warning) Unwrap() error

Jump to

Keyboard shortcuts

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