Documentation
¶
Index ¶
- func As(err error, target any) bool
- func Is(err, target error) bool
- func Last(err error, target any) bool
- func New(text string) error
- func ToLogrus(err error) logrus.Fields
- func ToMap(err error) map[string]interface{}
- func Unwrap(err error) error
- func WithStack(err error) error
- func Wrap(err error, msg string) error
- func Wrapf(err error, format string, a ...any) error
- type HasFields
- type HasFormat
- type WithFields
Constants ¶
This section is empty.
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 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 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.WithFields(errors.ToLogrus(err)).WithField("tid", 1).Error(err)
func ToMap ¶
ToMap Returns the context for the underlying error as map[string]interface{} If no context is 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 WithStack ¶
WithStack annotates err with a stack trace at the point WithStack was called. If err is nil, WithStack returns nil.
Types ¶
type HasFields ¶
type HasFields interface {
Fields() map[string]interface{}
}
HasFields Implement this interface to pass along unstructured context to the logger
type WithFields ¶
type WithFields map[string]interface{}
WithFields Creates errors that conform to the `HasFields` interface
func (WithFields) Error ¶
func (f WithFields) Error(msg string) error
func (WithFields) Errorf ¶
func (f WithFields) Errorf(format string, args ...interface{}) error
func (WithFields) WithStack ¶
func (f WithFields) WithStack(err error) error
WithStack returns an error annotating err with a stack trace at the point WithStack is called If err is nil, WithStack returns nil.