errors

package
v3.8.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: MIT Imports: 3 Imported by: 176

Documentation

Index

Constants

View Source
const (
	UnknownStack = "unknown"
)

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:

type causer interface {
       Cause() error
}

If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.

func Errorf

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

Errorf formats according to a format specifier and returns the string as a value that satisfies error. Errorf also records the stack trace at the point it was called.

func From

func From(err error, fields map[string]interface{}) error

From returns an error annotating err with a stack trace at the point From is called, and the provided fields.

If err is nil, From returns nil.

func FromPanic

func FromPanic(rec interface{}) error

FromPanic extracts the err from the result of a recover() call. If rec is not actually an error - a new error will be created, formatting the `rec` as "%s".

func GetFields

func GetFields(err error) map[string]interface{}

GetFields returns the underlying fields of the error and its nested cause-errors, if possible. An error value has fields if it (or any of its nested cause) implements the following interface:

type fieldsProvider interface {
       GetFields() F
}

If the error and all of its nested causes do not implement GetFields, empty fields map will be returned.

func GetStack

func GetStack(err error) string

GetStack returns the string representation of stacktrace of the provided error (see getErrorStack func for stack retrieving details).

If the provided error does not provide stack, GetStack will try to retrieve stack from its causer, then from causer of its cause, and so one.

If no stack was provided by any of the causers, the value of `UnknownStack` const will be returned.

func New

func New(msg string) error

New returns an error with the supplied message. New also records the stack trace at the point it was called.

func WithStack

func WithStack(err error) error

WithStack annotates err with a stack trace at the point WithStack was called. If err is nil, WithStack returns nil.

func Wrap

func Wrap(err error, msg string, errorFields ...map[string]interface{}) error

Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message.

Fields can optionally be added. If provided multiple - fields will be merged.

If err is nil, Wrap returns nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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