Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // As finds the first error in err's chain that matches target, and if so, // sets target to that error value and returns true. // // 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. // // As will panic if target is not a non-nil pointer to either a type that // implements error, or to any interface type. As returns false if err is // nil. As = errors.As // 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. Is = errors.Is // New returns an error that formats as the given text. // Each call to New returns a distinct error value even if the text is // identical. New = errors.New // 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. Unwrap = errors.Unwrap )
Functions ¶
func MainModule ¶
func MainModule() string
MainModule returns the path of the currently-running binary's main module, as defined in the go.mod file. If not built with module support, returns "".
func RelativeModule ¶
RelativeModule replaces occurrences of `home` inside `modName` with a tilde "~". If `home` is the empty string or if `modName` is not a child of home, just return `modName` without changing it.
func Stack ¶
Stack returns a slice of all the errors found by recursively calling Unwrap() on the provided error. Errors causing other errors appear later.
func StackString ¶
StackString recursively calls Unwrap() on the given error and stringifies all the errors in the chain.
The stringification adds location prefixes to errors that additionally implement `FuncInfo() FuncInfo` and optionally `ArgStringer() interface{ String() string }`.
The stringification can be overridden if the error implements `StackString() string`.
func StackStringAt ¶
StackStringAt returns one level of StackString.
Types ¶
type Builder ¶
type Builder interface { Errorf(msg string, args ...interface{}) error Wrap(err error, msg string, args ...interface{}) Wrapped }
Builder implementors can make and wrap errors.
BuiltinBuilder has no frills. It is a proxy to built-in go packages.
func NewBuilder ¶
NewBuilder returns an error builder that attaches info about the function where the error happened, and the args with which the function was called.
func NewLazyBuilder ¶
NewLazyBuilder SHOULD NOT be used unless it is known that NewBuilder won't work. Frequent undisciplined usage of NewLazyBuilder can lead to poor code maintainability. It is similar to NewBuilder, except that the embedded ArgStringer()s do their formatting work lazily when the error is formatted for display, rather than up-front when the Builder is initialized. This can be important for performance in functions called thousands of times per second, but misleading debug messages can result if the arguments have changed since the function was first called. As a debug warning, any args are labeled "<lazy>" by the ArgStringer().
type FuncInfo ¶
FuncInfo identifies a line of code, as provided by go runtime package functions.
func NewFuncInfo ¶
NewFuncInfo ascends the number of stack frames indicated by calldepth and returns a FuncInfo describing the location of that line of code. A calldepth of 0 refers to the invocation of NewFunInfo itself.
type Group ¶
type Group []error
Group allows treating a slice of errors as an error. This is useful when many errors together lead to one error downstream. For example, a network fetch might fail only if all the mirrors fail to respond.
func (Group) Error ¶
Error formats a []error as a list of errors if len() is 2 or more, otherwise as a single error if len() is 1, otherwise as nothing if len() is 0.
func (Group) StackString ¶
StackString formats a []error as a recursive list of StackString-ed errors if len() is 2 or more, otherwise as a single StackString-ed error if len() is 1, otherwise as nothing if len() is 0.