Documentation
¶
Overview ¶
Package errors provides wrapped errors with stack trace.
Index ¶
- Constants
- func As(err error, target interface{}) bool
- func Cause(e error) error
- func Code(e error) int
- func EffectiveCode(e error) int
- func Errorf(format string, args ...interface{}) error
- func Is(err, target error) bool
- func Msg(e error) string
- func New(msg string) error
- func NewWithCode(code int, msg string) error
- func NewWithCodef(code int, format string, args ...interface{}) error
- func Newf(format string, args ...interface{}) error
- func ResetCfg()
- func SetCfg(c *Config)
- func Unwrap(err error) error
- func Wrap(e error, msg string) error
- func WrapWithCode(e error, code int, msg string) error
- func WrapWithCodef(e error, code int, format string, args ...interface{}) error
- func Wrapf(e error, format string, args ...interface{}) error
- type Config
- type StackTrace
Constants ¶
const ( // UnknownCode is the error code for unspecified errors. UnknownCode = math.MinInt32 // Success is the success prompt string. Success = "success" )
Variables ¶
This section is empty.
Functions ¶
func As ¶
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.
func Cause ¶
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 Code ¶
Code function returns the error code associated with an error object if it is of type *baseError. If the error object is not of type *baseError, it returns the minimum value of int32.
func EffectiveCode ¶
EffectiveCode returns the first valid error code from the error chain. If error object encountered is not of type *baseError, it will return UnknownCode.
func Errorf ¶
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 Is ¶
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.
func Msg ¶
Msg function returns the error message associated with an error object if it is of type *baseError. If the error object is not of type *baseError, it returns it's Error().
func NewWithCode ¶
NewWithCode creates a new error with a stack trace, using the provided code and message.
func NewWithCodef ¶
NewWithCodef creates a new error with a stack trace, the provided code, format specifier and arguments. This function has the same functionality as the NewWithCode function.
func Newf ¶
Newf creates a new error with the provided format specifier and arguments. It has the same functionality as New function
func Unwrap ¶
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.
func Wrap ¶
Wrap function wraps the incoming error with stack information and message. If the incoming err already has a stack, the stack will not be set again. If the incoming err is nil, Wrap will return nil.
func WrapWithCode ¶
WrapWithCode function wraps the incoming error with stack information, code and message. If the incoming err already has a stack, the stack will not be set again. If the incoming err is nil, WrapWithCode will return nil.
func WrapWithCodef ¶
WrapWithCodef function wraps the incoming error with stack information, code, format specifier and arguments. This function has the same functionality as the WrapWithCode function.
Types ¶
type Config ¶
type Config struct { StackDepth int // StackDepth specifies the depth of the function call stack trace. Default value is 10. ErrorConnectionFlag string // ErrorConnectionFlag specifies the error connection flag string. Default value is "\nCaused by: ". }
Config represents the configuration options.
type StackTrace ¶
StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
func (StackTrace) Format ¶
func (st StackTrace) Format(s fmt.State, verb rune)
Format formats the stack of Frames according to the fmt.Formatter interface.
%s lists source files for each Frame in the stack %v lists the source file and line number for each Frame in the stack
Format accepts flags that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.