github.com/rogpeppe/errors
The juju/errors provides an easy way to annotate errors without losing the orginal error context. The package is based on github.com/juju/errgo and embeds the errgo.Err type. The exported New and Errorf functions is 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. Often when you want to check to see if an error is of a particular type, a helper function is exported by the package that returned the error, like the `os` package. The underlying cause of the error is available using the Cause function, or you can test the cause with the Check function. The result of the Error() call on the 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. If you are creating the errors, you can simply call: This function will return an error that contains the annotation stack and records the file, line and function from the place where the error is created. 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.
proxy.golang.org
v0.0.0-20140925100448-23a9401bffac
over 11 years ago
1
Links
| Registry | proxy.golang.org |
| Source | Repository |
| Docs | Documentation |
| JSON API | View JSON |
| CodeMeta | codemeta.json |
Package Details
| PURL |
pkg:golang/github.com/rogpeppe/errors
spec |
| License | LGPL-3.0 |
| Namespace | github.com/rogpeppe |
| First Release | over 11 years ago |
| Last Synced | 13 days ago |