package errs
import "github.com/zeebo/errs"
Package errs provides a simple error package with stack traces.
Index ¶
- func Combine(errs ...error) error
- func Is(err, target error) bool
- func IsFunc(err error, is func(err error) bool) bool
- func New(format string, args ...interface{}) error
- func Unwrap(err error) error
- func Wrap(err error) error
- func WrapP(err *error)
- type Causer
- type Class
- func Classes(err error) (classes []*Class)
- func (c *Class) Has(err error) bool
- func (c *Class) Instance() error
- func (c *Class) New(format string, args ...interface{}) error
- func (c *Class) Wrap(err error) error
- func (c *Class) WrapP(err *error)
- type Group
- type Namer
Functions ¶
func Combine ¶
Combine combines multiple non-empty errors into a single error.
func Is ¶
Is checks if any of the underlying errors matches target
func IsFunc ¶
IsFunc checks if any of the underlying errors matches the func
func New ¶
New returns an error not contained in any class. This is the same as calling fmt.Errorf(...) except it captures a stack trace on creation.
func Unwrap ¶
Unwrap returns the final, most underlying error, if any, or just the error.
Deprecated: Prefer errors.Is() and errors.As().
func Wrap ¶
Wrap returns an error not contained in any class. It just associates a stack trace with the error. Wrap returns nil if err is nil.
func WrapP ¶
func WrapP(err *error)
WrapP stores into the error pointer if it contains a non-nil error an error not contained in any class. It just associates a stack trace with the error. WrapP does nothing if the pointer or pointed at error is nil.
Types ¶
type Causer ¶
type Causer interface{ Cause() error }
Causer is implemented by all errors returned in this package. It returns the underlying cause of the error, or nil if there is no underlying cause.
Deprecated: check for the 'Unwrap()' interface from the stdlib errors package instead.
type Class ¶
type Class string
Class represents a class of errors. You can construct errors, and check if errors are part of the class.
func Classes ¶
Classes returns all the classes that have wrapped the error.
func (*Class) Has ¶
Has returns true if the passed in error (or any error wrapped by it) has this class.
func (*Class) Instance ¶
Instance creates a class membership object which implements the error interface and allows errors.Is() to check whether given errors are (or contain) an instance of this class.
This makes possible a construct like the following:
if errors.Is(err, MyClass.Instance()) { fmt.Printf("err is an instance of MyClass") }
..without requiring the Class type to implement the error interface itself, as that would open the door to sundry misunderstandings and misusage.
func (*Class) New ¶
New constructs an error with the format string that will be contained by this class. This is the same as calling Wrap(fmt.Errorf(...)).
func (*Class) Wrap ¶
Wrap returns a new error based on the passed in error that is contained in this class. Wrap returns nil if err is nil.
func (*Class) WrapP ¶
WrapP stores into the error pointer if it contains a non-nil error an error contained in this class. WrapP does nothing if the pointer or pointed at error is nil.
type Group ¶
type Group []error
Group is a list of errors.
func (*Group) Add ¶
Add adds non-empty errors to the Group.
func (Group) Err ¶
Err returns an error containing all of the non-nil errors. If there was only one error, it will return it. If there were none, it returns nil.
type Namer ¶
Namer is implemented by all errors returned in this package. It returns a name for the class of error it is, and a boolean indicating if the name is valid.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
errdata | Package errdata helps with associating some data to error classes |
- Version
- v1.4.0 (latest)
- Published
- May 8, 2023
- Platform
- js/wasm
- Imports
- 4 packages
- Last checked
- 2 days ago –
Tools for package owners.