errors

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: Apache-2.0 Imports: 4 Imported by: 13

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

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

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.

func Cause

func Cause(err error) error

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

func Is

func Is(err, target error) bool

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.

func Newf

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

Newf formats according to a format specifier and returns a new error with a stacktrace with 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.

If no args have been passed, it is same as `New` function without formatting. Character like '%' still has to be escaped in that scenario.

func Unwrap

func Unwrap(err error) error

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.

func Wrapf

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

Wrapf returns a new error by formatting the error message with the supplied format specifier and wrapping another error with a stacktrace containing recent call frames.

If cause is nil, this is the same as fmt.Errorf. If no args have been passed, it is same as `Wrap` function without formatting. Character like '%' still has to be escaped in that scenario.

Types

This section is empty.

Jump to

Keyboard shortcuts

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