All Projects → monzo → terrors

monzo / terrors

Licence: MIT license
No description, website, or topics provided.

Programming Languages

go
31211 projects - #10 most used programming language

terrors

Build Status GoDoc

Terrors is a package for wrapping Golang errors. Terrors provides additional context to an error, such as an error code and a stack trace.

Terrors is built and used at Monzo.

Usage

Terrors can be used to wrap any object that satisfies the error interface:

terr := terrors.Wrap(err, map[string]string{"context": "my_context"})

Terrors can be instantiated directly:

err := terrors.New("not_found", "object not found", map[string]string{
	"context": "my_context"
})

Terrors offers built-in functions for instantiating Errors with common codes:

err := terrors.NotFound("config_file", "config file not found", map[string]string{
	"context": my_context
})

Terrors provides functions for matching specific Errors:

err := NotFound("handler_missing", "Handler not found", nil)
fmt.Println(Matches(err, "not_found.handler_missing")) // true

Retryability

Terrors contains the ability to declare whether or not an error is retryable. This property is derived from the error code if not specified explicitly.

When using the the wrapping functionality (e.g. Wrap, Augment, Propagate), the retryability of an error is preserved as expected. Importantly, it is also preserved when constructing a new error from a causal error with NewInternalWithCause.

API

Full API documentation can be found on godoc

Install

$ go get -u github.com/monzo/terrors

License

Terrors is licenced under the MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].