README.md 1.2 KB

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/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")