Documentation ¶
Index ¶
- Variables
- func As(err error, target any) bool
- func Flatten(err error) [][]error
- func GetCodes(err error) []string
- func GetKeyValues(err error) map[string]string
- func GetLastStackTrace(err error) (string, []string, bool)
- func Is(err, target error) bool
- func IsAny(err error, targets ...error) bool
- func Join(err ...error) error
- func New(msg string, ol ...Option) error
- func SetTraceConfig(config trace.StackConfig)
- func SetTraceConfigTesting(t testing.TB, config trace.StackConfig)
- func Unwrap(err error) error
- func Walk(err error, do func(error) bool)
- func Wrap(err error, msg string, ol ...Option) error
- type ErrorOption
- type Option
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Flatten ¶
Flatten walks the error tree, creating a path for each leaf of the tree if the tree looks like this:
── a └── b ├── c │ └── e │ └── f └── d ├── g └── h
Then the paths we will get are: [a, b, c, e, f] [a, b, d, g] [a, b, d, h]
func GetCodes ¶
GetCodes returns the stack of error codes in the given jettison error chain. The error codes are returned in reverse-order of calls to Wrap(), i.e. the code of the latest wrapped error comes first in the list.
func GetKeyValues ¶
GetKeyValues returns all embedded key value info in the error
func SetTraceConfig ¶
func SetTraceConfig(config trace.StackConfig)
func SetTraceConfigTesting ¶
func SetTraceConfigTesting(t testing.TB, config trace.StackConfig)
Types ¶
type ErrorOption ¶
func (ErrorOption) ApplyToError ¶
func (o ErrorOption) ApplyToError(je *internal.Error)
type Option ¶
func WithCode ¶
WithCode sets an error code on the error. A code should uniquely identity an error, the intention being to provide an equality check for jettison errors (see Is() for more details). The default code (the error message) doesn't provide strong unique guarantees.
func WithStackTrace ¶
func WithStackTrace() Option
WithStackTrace will add a new stack trace to this error
func WithoutStackTrace ¶
func WithoutStackTrace() Option
WithoutStackTrace clears any automatically populated stack trace. New always populates a stack trace and Wrap will if no sub error has a trace.
This Option is useful for sentinel errors which have a useless init-time stack trace. Removing it allows a stacktrace to be added when it is Wrapped.
Example
var ErrFoo = errors.New("foo", errors.WithoutStackTrace()) // Clear useless init-time stack trace. func bar() error { return errors.Wrap(ErrFoo, "bar") // Wrapping ErrFoo adds a proper stack trace. }