errutil

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

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.1

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 New

func New(msg string) error

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

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. 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.

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.

func Wrap

func Wrap(err error, msg string) error

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

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.

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.

Jump to

Keyboard shortcuts

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