package errors
Import Path
github.com/efficientgo/core/errors (on go.dev)
Dependency Relation
imports 4 packages, and imported by 2 packages
Involved Source Files
Package errors provides basic utilities to manipulate errors with a useful stacktrace. It combines the
benefits of errors.New and fmt.Errorf world into a single package. It is an improved and minimal version of the popular
https://github.com/pkg/errors (archived) package allowing reliable wrapping of errors with stacktrace. Unfortunately,
the standard library recommended error wrapping using `%+w` is prone to errors and does not support stacktraces.
errors.go
stacktrace.go
Package-Level Functions (total 8)
As is a wrapper of built-in errors.As. It finds the first 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.
Cause returns the result of repeatedly calling the Unwrap method on err, if err's
type implements an Unwrap method. Otherwise, Cause returns the last encountered error.
The difference between Unwrap and Cause is the first one performs unwrapping of one level
but Cause returns the last err (whether it's nil or not) where it failed to assert
the interface containing the Unwrap method.
This is a replacement of errors.Cause without the causer interface from pkg/errors which
actually can be sufficed through the errors.Is function. But considering some use cases
where we need to peel off all the external layers applied through errors.Wrap family,
it is useful ( where external SDK doesn't use errors.Is internally).
Is is a wrapper of built-in errors.Is. It 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.
New returns a new error with a stacktrace of recent call frames. Each call to New
returns a distinct error value even if the text is identical. An alternative of
the errors.New function from github.com/pkg/errors.
Newf is like New, but it formats input according to a format specifier.
An alternative of the fmt.Errorf function.
If no args have been passed, it is same as `New` function without formatting. Character like
'%' still has to be escaped in that scenario.
Unwrap is a wrapper of built-in errors.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.
Wrap returns a new error, which wraps another error with a stacktrace containing recent call frames.
If cause is nil, it does not produce the error, similar to errors.Wrap from github.com/pkg/errors was doing.
Still, avoid `errors.Wrap(nil, "...") patterns as it can lead to inefficiencies while constructing arguments
to format as well readability issues. We keep this behaviour to make sure it's a drop-in replacement.
Wrapf is like Wrap but the message is formatted with the supplied format specifier.
If no args have been passed, it is same as `Wrap` function without formatting.
Character like '%' still has to be escaped in that scenario.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |