Drop-in replacement for the Go SDK "errors" package with some extra sugar.
This package exports the exact same symbols as exported by the Go SDK standard library errors
package, with few additions:
- The
New
function returns an instance ofErrorWithMeta
interface, which extendserror
with methods for adding tags and labels (see below) - The
Errorf
function is added, a proxy tofmt.Errorf
but also returns an instance ofErrorwithMeta
but with methods for adding tags and labels (see below) - The
Tag
andLabel
structs, used for adding metadata to errors - The
LabelOf
function to create aLabel
instance. - The
HasTag
,HasLabel
,GetLabel
andGetLabels
functions for getting anerror
metadata (if any)
This package allows adding tags metadata to errors, so that later decisions can be made based on whether a certain error
has a certain tag or not (e.g. user-facing
, abort
, etc).
To add tags metadata to an error, do this:
package myPackage
import "github.com/arikkfir/errors"
func failsWithErrorForTheUser() error {
return errors.New("an error").WithMeta(errors.Tag("user-facing"))
}
func failsWithCustomerLabel() error {
return errors.New("an error").WithMeta(errors.LabelOf("file", "/var/db/bad-file"), errors.LabelOf("customer", "3h18ksk2"))
}