errs – github.com/zeebo/errs Index | Files | Directories

package errs

import "github.com/zeebo/errs"

Package errs provides a simple error package with stack traces.

Index

Functions

func Combine

func Combine(errs ...error) error

Combine combines multiple errors into a single error.

func New

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

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

func Unwrap(err error) error

Unwrap returns the underlying error, if any, or just the error.

func Wrap

func Wrap(err error) error

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.

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.

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

func Classes(err error) (classes []*Class)

Classes returns all the classes that have wrapped the error.

func (*Class) Has

func (c *Class) Has(err error) bool

Has returns true if the passed in error was wrapped by this class.

func (*Class) New

func (c *Class) New(format string, args ...interface{}) error

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

func (c *Class) Wrap(err error) error

Wrap returns a new error based on the passed in error that is contained in this class. Wrap returns nil if err is nil.

type Group

type Group []error

Group is a list of errors.

func (*Group) Add

func (group *Group) Add(errs ...error)

Add adds non-empty errors to the Group.

func (Group) Err

func (group Group) Err() error

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

type Namer interface{ Name() (string, bool) }

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

errs.go group.go

Directories

PathSynopsis
errdataPackage errdata helps with associating some data to error classes
Version
v1.1.1
Published
Dec 19, 2018
Platform
js/wasm
Imports
3 packages
Last checked
1 week ago

Tools for package owners.