# README
errors
A package that provides enriched errors. It uses the same conventions and extends the Go standard errors package.
Install
go get -u github.com/aukilabs/go-tooling/pkg/errors
Usage
Create
err := errors.New("error message") // With a message.
err := errors.Newf("error message with format: %v", 42) // With a formatted message.
Enrich With A Custom Type
err := errors.New("handling http request failed").WithType("httpError")
Enrich With Tags
err := errors.New("handing http request failed").
WithTag("method", "GET").
WithTag("path", "/cookies").
WithTag("code", 401)
Wrap Another Error
err := errors.New("handling http request failed").Wrap(fmt.Errorf("a fake simple http error"))
Compose Multiple Enrichments
err := errors.New("handing http request failed").
WithType("httpError").
WithTag("method", "GET").
WithTag("path", "/cookies").
WithTag("code", 401).
Wrap(fmt.Errorf("a fake simple http error"))
Get Error Type
var err error
t := errors.Type(err)
Get Error Tag
var err error
foo := errors.Tag(err, "foo")
# Functions
As finds the first error in err's chain that matches target, and if one is found, sets target to that error value and returns true.
HasType reports whether any error in err's chain matches the given type.
Is reports whether any error in err's chain matches target.
New returns an error with the given message that can be enriched with a type and tags.
Newf returns an error with the given formatted message that can be enriched with a type and tags.
SetIndentEncoder is a helper function that set the error encoder to a function that uses json.MarshalIndent.
SetInlineEncoder is a helper function that set the error encoder to json.Marshal.
Tag returns the first tag value in err's chain that matches the given key.
Type returns the type of the error.
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error.
# Variables
The function used to encode errors and their tags.