Documentation
¶
Index ¶
- Constants
- func As(err error, target any) bool
- func Cause(err error) error
- func Errorf(format string, a ...any) error
- func Is(err, target error) bool
- func Last(err error, target any) bool
- func New(text string) error
- func Stack(err error) error
- func ToLogrus(err error) logrus.Fields
- func ToMap(err error) map[string]any
- func Unwrap(err error) error
- func Wrap(err error, msg string) error
- func WrapFields(err error, f Fields, msg string) error
- func WrapFieldsf(err error, f Fields, format string, args ...any) error
- func Wrapf(err error, format string, a ...any) error
- type Fields
- type HasFields
- type HasFormat
Constants ¶
const NoMsg = ""
NoMsg is a small indicator in the code that "" is intentional and there is no message include with the Wrap()
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.
func Errorf ¶ added in v0.1.4
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
If the format specifier includes a %w verb with an error operand, the returned error will implement an Unwrap method returning the operand. It is invalid to include more than one %w verb or to supply it with an operand that does not implement the error interface. The %w verb is otherwise a synonym for %v.
func Last ¶
Last finds the last error in err's chain that matches target, and if one is found, sets target to that error value and returns true. Otherwise, it returns false.
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(any) bool` such that As(target) returns true.
An error type might provide an As() method so it can be treated as if it were a different error type.
Last panics if target is not a non-nil pointer to either a type that implements error, or to any interface type.
NOTE: Last() is much slower than As(). Therefore As() should always be used unless you absolutely need Last() to retrieve the last error in the error chain that matches the target.
func New ¶
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.
func Stack ¶ added in v0.1.4
Stack annotates err with a stack trace at the point Stack was called. If err is nil, Stack returns nil.
func ToLogrus ¶
ToLogrus Returns the context and stacktrace information for the underlying error as logrus.Fields{} returns empty logrus.Fields{} if err has no context or no stacktrace
logrus.Fields(errors.ToLogrus(err)).WithField("tid", 1).Error(err)
func ToMap ¶
ToMap Returns the fields for the underlying error as map[string]any If no fields are available returns nil
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 WrapFields ¶ added in v0.1.4
WrapFields returns a new error wrapping the provided error with fields and a message.
func WrapFieldsf ¶ added in v0.1.4
WrapFieldsf is identical to WrapFields but with optional formatting
Types ¶
type Fields ¶ added in v0.1.4
Fields Creates errors that conform to the `HasFields` interface
func (Fields) Stack ¶ added in v0.1.4
Stack returns an error annotating err with a stack trace at the point Stack is called. If err is nil, Stack returns nil.