Documentation ¶
Overview ¶
Package errors implements functions for handling errors It implements the same functions as the standard "errors" package, with a few added ones for ease of use
Except where noted, functions that take a nil as their error will retrun nil, and do so very cheaply, so that you can use potentially expensive calls in main path.
See godoc.org/errors for in-depth details about Is, As, Unwrap and New
Index ¶
- func AddStack(err error) error
- func Append(err error, others ...error) error
- func AppendInto(err *error, errs ...error)
- func As(err error, target interface{}) bool
- func AutoWrap(err error) error
- func CallInto(err *error, fn func() error)
- func Is(err, target error) bool
- func New(text string) error
- func RecoverInto(err *error)
- func Unwrap(err error) error
- func Wrap(err error, msg string) error
- func Wrapf(err error, msg string, a ...interface{}) error
- type Error
- type Multi
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddStack ¶
AddStack wraps err to add a stack trace
Quite a bit more expensive call compared to Wrap, but extremely useful, and run time should still be around the microsecond (few nanoseconds for Wrap)
If err is nil, returns nil ¶
If call stack is extremely deep (10k+), has very poor performance (but you shouldn't record call stack in recursive functions anyway).
func Append ¶
Append returns a *Multi (or nil) containing all errors
Use like you would append: err = Append(err, myerror)
if err is already a *Multi, appends to it otherwise, create a *Multi with err as first error.
func AppendInto ¶
AppendInto appends errs into err, useful for repetitive appends.
func AutoWrap ¶
AutoWrap returns an error that wraps err
Additionally, it adds the name of the caller function (and package) to the message
Quite slower than manual Wrap("package.Func", err).
func CallInto ¶
CallInto appends fn() into err
Useful for defer : defer errors.CallInto(&err, file.Close).
func New ¶
New returns an error that formats as the given text Each call to New returns a distinct error value even if the text is identical.
func RecoverInto ¶
func RecoverInto(err *error)
RecoverInto tries to recover, and appends a representation of the error to err. If the recovered value is not an error, will create a new error based on fmt.Sprint(value)
Use like: defer RecoverInto(&err).
func 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.
Types ¶
type Error ¶
Error represents a simple error and its message.
It may also optionally hold a wrapped error, and/or a stack trace.