Documentation ¶
Overview ¶
Package failure allows to create more detailed error values than with errors.New() or fmt.Errorf().
The errors package allows to easily created formatted errors with New() like with the fmt.Errorf() function, but also containing the location and a code. The creation of error nessages is like with fmt.Errorf().
If an error alreay exists use Annotate(). This way the original error will be stored and can be retrieved with Annotated(). Also its error message will be appended to the created error separated by a colon.
All errors additionally contain their package, filename and line number. These information can be retrieved using Location(). In case of a chain of annotated errors those can be retrieved as a slice of errors with Stack().
Index ¶
- func All(err error) []error
- func Annotate(err error, msg string, args ...interface{}) error
- func Annotated(err error) error
- func Collect(errs ...error) error
- func Contains(err error, substr string) bool
- func DoAll(err error, f func(error))
- func First(existing, setting error) error
- func IsValid(err error) bool
- func Location(err error) (string, error)
- func New(msg string, args ...interface{}) error
- func Stack(err error) []error
- type Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Annotate ¶
Annotate creates an error wrapping another one together with a a code. If the passed one is nil, Annotate() also returns nil.
func Annotated ¶
Annotated returns the possibly annotated error. In case of a different error an invalid type error is returned.
func DoAll ¶
DoAll iterates the passed function over all stacked or collected errors or simply the one that's passed.
func First ¶
First checks the existing error for nil. If not it will be returned, otherwise the setting one. So usage is myStruct.err = failure.First(myStruct.err, newErr).
func Location ¶
Location returns the package and the file name as well as the line number of the error.