errutil

package
v1.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 17 Imported by: 7

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func As added in v1.2.0

func As(err error, target interface{}) bool

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

func AssertionFailedWithDepthf(depth int, format string, args ...interface{}) error

AssertionFailedWithDepthf creates an internal error with a stack trace collected at the specified depth. See the doc of `AssertionFailedf()` for more details.

func AssertionFailedf

func AssertionFailedf(format string, args ...interface{}) error

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

func HandleAsAssertionFailure(origErr error) error

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

func HandleAsAssertionFailureDepth(depth int, origErr error) error

HandleAsAssertionFailureDepth is like HandleAsAssertionFailure but the depth at which the call stack is captured can be specified.

func JoinWithDepth added in v1.10.1

func JoinWithDepth(depth int, errs ...error) error

JoinWithDepth constructs a Join error with the provided list of errors as arguments, and wraps it in a `WithStackDepth` to capture a stacktrace alongside.

func New

func New(msg string) error

New creates an error with a simple error message. A stack trace is retained.

Note: the message string is assumed to not contain PII and is included in Sentry reports. Use errors.Newf("%s", <unsafestring>) for errors strings that may contain PII information.

Detail output: - message via `Error()` and formatting using `%v`/`%s`/`%q`. - everything when formatting with `%+v`. - stack trace and message via `errors.GetSafeDetails()`. - stack trace and 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

func NewAssertionErrorWithWrappedErrf(origErr error, format string, args ...interface{}) error

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

func NewWithDepth(depth int, msg string) error

NewWithDepth is like New() except the depth to capture the stack trace is configurable. See the doc of `New()` for more details.

func NewWithDepthf

func NewWithDepthf(depth int, format string, args ...interface{}) error

NewWithDepthf is like Newf() except the depth to capture the stack trace is configurable. See the doc of `New()` for more details.

func Newf

func Newf(format string, args ...interface{}) error

Newf creates an error with a formatted error message. A stack trace is retained.

Note: the format string is assumed to not contain PII and is included in Sentry reports. Use errors.Newf("%s", <unsafestring>) for errors strings that may contain PII information.

See the doc of `New()` for more details.

func WithMessage

func WithMessage(err error, message string) error

WithMessage annotates err with a new message. If err is nil, WithMessage returns nil. The message is considered safe for reporting and is included in Sentry reports.

func WithMessagef

func WithMessagef(err error, format string, args ...interface{}) error

WithMessagef annotates err with the format specifier. If err is nil, WithMessagef returns nil. The message is formatted as per redact.Sprintf, to separate safe and unsafe strings for Sentry reporting.

func Wrap

func Wrap(err error, msg string) error

Wrap wraps an error with a message prefix. A stack trace is retained.

Note: the prefix string is assumed to not contain PII and is included in Sentry reports. Use errors.Wrapf(err, "%s", <unsafestring>) for errors strings that may contain PII information.

Detail output: - original error message + prefix via `Error()` and formatting using `%v`/`%s`/`%q`. - everything when formatting with `%+v`. - stack trace and message via `errors.GetSafeDetails()`. - stack trace and message in Sentry reports.

func WrapWithDepth

func WrapWithDepth(depth int, err error, msg string) error

WrapWithDepth is like Wrap except the depth to capture the stack trace is configurable. The the doc of `Wrap()` for more details.

func WrapWithDepthf

func WrapWithDepthf(depth int, err error, format string, args ...interface{}) error

WrapWithDepthf is like Wrapf except the depth to capture the stack trace is configurable. The the doc of `Wrapf()` for more details.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

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.

Note: the format string is assumed to not contain PII and is included in Sentry reports. Use errors.Wrapf(err, "%s", <unsafestring>) for errors strings that may contain PII information.

Detail output: - original error message + prefix via `Error()` and formatting using `%v`/`%s`/`%q`. - everything when formatting with `%+v`. - stack trace, format, and redacted details via `errors.GetSafeDetails()`. - stack trace, format, and redacted details in Sentry reports.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL