Documentation ¶
Overview ¶
Package errutil combines primitives from the library, the Go errors package and github.com/pkg/errors. It aims to serve as drop-in replacement to gitub.com/pkg/errors and replace the legacy implementation of `pgerrors`.
Index ¶
- func As(err error, target interface{}) bool
- func AssertionFailedWithDepthf(depth int, format string, args ...interface{}) error
- func AssertionFailedf(format string, args ...interface{}) error
- func HandleAsAssertionFailure(origErr error) error
- func HandleAsAssertionFailureDepth(depth int, origErr error) error
- func New(msg string) error
- func NewAssertionErrorWithWrappedErrDepthf(depth int, origErr error, format string, args ...interface{}) error
- func NewAssertionErrorWithWrappedErrf(origErr error, format string, args ...interface{}) error
- func NewWithDepth(depth int, msg string) error
- func NewWithDepthf(depth int, format string, args ...interface{}) error
- func Newf(format string, args ...interface{}) error
- func WithMessage(err error, message string) error
- func WithMessagef(err error, format string, args ...interface{}) error
- func Wrap(err error, msg string) error
- func WrapWithDepth(depth int, err error, msg string) error
- func WrapWithDepthf(depth int, err error, format string, args ...interface{}) error
- func Wrapf(err error, format string, args ...interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶ added in v1.2.1
As finds the first error in err's chain that matches the type to which target points, and if so, sets the target to its value and returns true. An error matches a type if it is assignable to the target type, or if it has a method As(interface{}) bool such that As(target) returns true. As will panic if target is not a non-nil pointer to a type which implements error or is of interface type.
The As method should set the target to its value and return true if err matches the type to which target points.
Note: this implementation differs from that of xerrors as follows: - it also supports recursing through causes with Cause(). - if it detects an API use error, its panic object is a valid error.
func AssertionFailedWithDepthf ¶
AssertionFailedWithDepthf creates an internal error with a stack trace collected at the specified depth. See the doc of `AssertionFailedf()` for more details.
func AssertionFailedf ¶
AssertionFailedf creates an internal error.
Detail is shown: - via `errors.GetSafeDetails()`, shows redacted strings. - when formatting with `%+v`. - in Sentry reports.
func HandleAsAssertionFailure ¶ added in v1.2.3
HandleAsAssertionFailure hides an error and turns it into an assertion failure. Both details from the original error and the context of the caller are preserved. The original error is not visible as cause any more. The original error message is preserved. See the doc of `AssertionFailedf()` for more details.
func HandleAsAssertionFailureDepth ¶ added in v1.2.3
HandleAsAssertionFailureDepth is like HandleAsAssertionFailure but the depth at which the call stack is captured can be specified.
func New ¶
New creates an error with a simple error message. A stack trace is retained.
Detail output: - message via `Error()` and formatting using `%v`/`%s`/`%q`. - everything when formatting with `%+v`. - stack trace (not message) via `errors.GetSafeDetails()`. - stack trace (not message) in Sentry reports.
func NewAssertionErrorWithWrappedErrDepthf ¶
func NewAssertionErrorWithWrappedErrDepthf( depth int, origErr error, format string, args ...interface{}, ) error
NewAssertionErrorWithWrappedErrDepthf is like NewAssertionErrorWithWrappedErrf but the depth at which the call stack is captured can be specified. See the doc of `AssertionFailedf()` for more details.
func NewAssertionErrorWithWrappedErrf ¶
NewAssertionErrorWithWrappedErrf wraps an error and turns it into an assertion error. Both details from the original error and the context of the caller are preserved. The original error is not visible as cause any more. The original error message is preserved. See the doc of `AssertionFailedf()` for more details.
func NewWithDepth ¶
NewWithDepth is like New() except the depth to capture the stack trace is configurable. See the doc of `New()` for more details.
func NewWithDepthf ¶
NewWithDepthf is like Newf() except the depth to capture the stack trace is configurable. See the doc of `New()` for more details.
func Newf ¶
Newf creates an error with a formatted error message. A stack trace is retained. See the doc of `New()` for more details.
func WithMessage ¶
WithMessage annotates err with a new message. If err is nil, WithMessage returns nil.
func WithMessagef ¶
WithMessagef annotates err with the format specifier. If err is nil, WithMessagef returns nil.
func Wrap ¶
Wrap wraps an error with a message prefix. A stack trace is retained.
Detail output: - original error message + prefix via `Error()` and formatting using `%v`/`%s`/`%q`. - everything when formatting with `%+v`. - stack trace (not message) via `errors.GetSafeDetails()`. - stack trace (not message) in Sentry reports.
func WrapWithDepth ¶
WrapWithDepth is like Wrap except the depth to capture the stack trace is configurable. The the doc of `Wrap()` for more details.
func WrapWithDepthf ¶
WrapWithDepthf is like Wrapf except the depth to capture the stack trace is configurable. The the doc of `Wrapf()` for more details.
func Wrapf ¶
Wrapf wraps an error with a formatted message prefix. A stack trace is also retained. If the format is empty, no prefix is added, but the extra arguments are still processed for reportable strings.
Detail output: - original error message + prefix via `Error()` and formatting using `%v`/`%s`/`%q`. - everything when formatting with `%+v`. - stack trace (not message) and redacted details via `errors.GetSafeDetails()`. - stack trace (not message) and redacted details in Sentry reports.
Types ¶
This section is empty.