Documentation ¶
Overview ¶
This package defines and implements an error interface that includes: definition of an error kind that can be referenced in error handlers; a chain of errors that are the causes of the current error; a stack trace. The stack trace is based on runtime/debug/Stack.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultKind = NewKind("Errx")
DefaultKind is used for on-the-fly construction of Errx instances.
Functions ¶
func PanicOnError ¶
func PanicOnError(err error)
func StackTraceOf ¶
StackTraceOf returns err.StackTrace() if err is of type Errx, an empty string otherwise.
func TODO ¶
This function is a placeholder for code to be implemented. It panics on execution, with an errx.Errx as the panic argument. It takes an optional string argument that is used as the message for the aforementioned error object. If a message is not provided, the default "missing implementation" is used.
Types ¶
type Errx ¶
type Errx interface { error // Kind returns the error's Kind Kind() *Kind // Cause returns the error's cause, which may be nil. // This method is named for consistency with Go's standard errors package. Unwrap() error // Args returns the arguments that are substituted into KindMsg(). Args() []any // RawMsg returns the raw message for the error, i.e., without args substitution. RawMsg() string // Msg returns the error's message with arguments substituted. Msg() string // RecursiveMsg returns a message string that combines the error messages of all errors // in the error's cause chain (which includes the error itself). RecursiveMsg() string // ErrxChain returns the error followed by all its preceding causes of type Errx. ErrxChain() []Errx // CauseChain returns the error followed by all its preceding causes. CauseChain() []error // InnermostCause returns the innermost cause in the error's cause chain. InnermostCause() error // InnermostErrx returns the innermost cause of type Errx in the error's cause chain. InnermostErrx() Errx // StackTrace returns a stack trace from the point where the error was created. StackTrace() string // Customize changes the raw error message and arguments of the receiver. // Returns the modified receiver. Customize(rawMsg string, args ...any) Errx }
Errx defines an error type with support for error kinds, a cause chain, recursive error message, and a stack trace.
func ErrxOf ¶
ErrxOf creates an Errx from r. If r is nil, nil is returned. If r is an Errx, r is returned. If r is an error, NewErrx is used to instantiate an Errx with r as its cause. Otherwise, NewErrx is used to instantiate an Errx with nil as the cause argument and r's string rendering as the msg argument.
type Kind ¶
type Kind struct {
// contains filtered or unexported fields
}
Kind encapsulates an error messag string (possibly with argument placeholders) and a list of direct super-kinds it is to be considered to be related to.
func (*Kind) Decorate ¶
Decorate instantiates an Errx from a Kind pointer. The cause argument must be an Errx. The difference between Make and Decorate is that Make sets a new stack trace at the point of instantiation while Decorate effectively relies on the the stack trace provided by causes or its most recent cause which has a stack trace.
func (*Kind) IsSubKindOf ¶
func (*Kind) Make ¶
Make instantiates an Errx from a Kind pointer, creating a stack trace at the point of instantiation.
func (*Kind) SuperKinds ¶
SuperKinds returns the set of all super-kinds of the receiver, including the receiver itself.