Documentation ¶
Index ¶
- Variables
- func If(err error, rule Rule, fn func(err error))
- func IfMarked(err error, m *Marker, fn func(err error))
- func Mark(err error, m *Marker) error
- func MarkIf(err error, m *Marker, rule Rule) error
- func MarkShort(err error) error
- func MarkShortIf(err error, rule Rule) error
- func MarkTransient(err error) error
- func MarkTransientIf(err error, rule Rule) error
- func MarkUser(err error) error
- func MarkUserIf(err error, rule Rule) error
- func Marked(err error, m *Marker) bool
- func MarkedShort(err error) bool
- func MarkedTransient(err error) bool
- func MarkedUser(err error) bool
- func Matches(err error, rule Rule) bool
- func Unless(err error, rule Rule, fn func(err error))
- func UnlessMarked(err error, m *Marker, fn func(err error))
- type Marker
- type MarkerSet
- type Rule
- type RuleFunc
Constants ¶
This section is empty.
Variables ¶
var ( // Short is a Marker for indicating that the representation of an error // should be abbreviated. In the case of this package, an error marked Short // will have the marker prefixes elided from the error message. Short = NewMarker("short") // RuleMarkedShort is a Rule that matches an error if that error has been // marked Short. RuleMarkedShort = RuleMarked(Short) )
var ( // Transient is a Marker for indicating that a given error is temporary in // nature. This is typically used to ask a client to retry work in the // future. Transient = NewMarker("transient") // RuleMarkedTransient is a Rule that matches an error if that error has // been marked Transient. RuleMarkedTransient = RuleMarked(Transient) )
var ( // User is a Marker for indicating that an error was caused by user action // and not by a system error. It is typically used to ask a user to change // application input to remedy the problem. User = NewMarker("user") // RuleMarkedUser is a Rule that matches an error if the error has been // marked as a user error. RuleMarkedUser = RuleMarked(User) )
var RuleAlways = RuleAll()
RuleAlways succeeds against every error.
var RuleNever = RuleAny()
RuleNever fails against every error.
Functions ¶
func MarkShortIf ¶
MarkShortIf marks an error as short if the error matches the given Rule.
func MarkTransientIf ¶
MarkTransientIf marks an error as transient if the error matches the given Rule.
func MarkUserIf ¶
MarkUserIf marks an error as a user error if the error matches the given Rule.
func MarkedShort ¶
MarkedShort returns true if the given error has been marked short.
func MarkedTransient ¶
MarkedTransient returns true if the given error has been marked transient.
func MarkedUser ¶
MarkedUser returns true if the given error has been marked as a user error.
func UnlessMarked ¶
UnlessMarked runs a callback function if the error is not marked with the given Marker.
Types ¶
type Marker ¶
type Marker struct {
// contains filtered or unexported fields
}
Marker represents a named identifier that logically groups one or more arbitrary errors.
Note that Markers are intentionally not comparable by value, that is, NewMarker("foo") != NewMarker("foo"). Markers should generally be declared in package scope.
type MarkerSet ¶
type MarkerSet struct {
// contains filtered or unexported fields
}
MarkerSet is a unique collection of Markers.
func NewMarkerSet ¶
NewMarkerSet creates a collection of Markers with the given values after deduplicating.
It is valid to work with nil values of *MarkerSet. All methods of the struct check for a nil receiver first.
type Rule ¶
Rule tests an error against an arbitrary condition.
It is useful for deciding when an error should be marked with a given Marker.
func RuleAll ¶
RuleAll applies several rules in sequence. If one of the rules returns false, this rule also returns false. Otherwise, this rule returns true.
func RuleAny ¶
RuleAny applies several rules in sequence. If one of the rules returns true, this rule also returns true. Otherwise, this rule returns false.
func RuleMarked ¶
RuleMarked matches an error if the error has been marked with the given Marker.
func RulePredicate ¶
RulePredicate evalutes a delegate rule when a predicate is satisfied at the time an error is passed to the rule. It returns false if the predicate is not satisfied.