Package Usage: go: github.com/juju/errors
Package errors provides an easy way to annotate errors without losing the
original error context.
The exported `New` and `Errorf` functions are designed to replace the
`errors.New` and `fmt.Errorf` functions respectively. The same underlying
error is there, but the package also records the location at which the error
was created.
A primary use case for this library is to add extra context any time an
error is returned from a function.
This instead becomes:
which just records the file and line number of the Trace call, or
which also adds an annotation to the error.
When you want to check to see if an error is of a particular type, a helper
function is normally exported by the package that returned the error, like the
`os` package does. The underlying cause of the error is available using the
`Cause` function.
The result of the `Error()` call on an annotated error is the annotations joined
with colons, then the result of the `Error()` method for the underlying error
that was the cause.
Obviously recording the file, line and functions is not very useful if you
cannot get them back out again.
will return something like:
The first error was generated by an external system, so there was no location
associated. The second, fourth, and last lines were generated with Trace calls,
and the other two through Annotate.
Sometimes when responding to an error you want to return a more specific error
for the situation.
This returns an error where the complete error stack is still available, and
`errors.Cause()` will return the `NotFound` error.
1 version
Latest release: about 3 years ago
1,596 dependent packages
View more package details: https://packages.ecosystem.code.gouv.fr/registries/proxy.golang.org/packages/github.com/juju/errors