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
Newfunction returns an instance ofErrorWithMetainterface, which extendserrorwith methods for adding tags and labels (see below) - The
Errorffunction is added, a proxy tofmt.Errorfbut also returns an instance ofErrorwithMetabut with methods for adding tags and labels (see below) - The
TagandLabelstructs, used for adding metadata to errors - The
LabelOffunction to create aLabelinstance. - The
HasTag,HasLabel,GetLabelandGetLabelsfunctions for getting anerrormetadata (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"))
}