Documentation ¶
Overview ¶
Package fate allows implementing "designing for failure" by introducing errors inside application logic by "tempting fate".
type Fate interface { // Tempt sometimes returns ErrTempt. Tempt() error }
Fate supports deterministic behavior for tests and probabilistic behavior for production.
The canonical usage pattern:
function multiStepLogic(state state.State, fate fate.Fate, arg int) error { r1, err := step1(state.Step1DB(), arg) if err != nil { return err } if err := fate.Tempt(); err != nil { return err } err := step2(state.Step2DB(), r1) if err != nil { return err } return fate.Tempt() }
Increasing the tangibility and probability of errors by regularly tempting fate both in production and tests, re-enforces the need for idempotent robust failure proof code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTempt = errors.New("tempt fate error", j.C("ERR_9f3adc780288ce11"))
ErrTempt is the error returned when tempting fate and losing.
Functions ¶
func SetConfig ¶
func SetConfig(opts ...option) func()
SetConfig sets the global config defined by the functional options. It returns an undo function mostly used for testing. Note configuring and using Fate instances is advised over global config.
func Tempt ¶
func Tempt() error
Tempt sometimes returns ErrTempt. Note this uses the global config, configuring and using Fate instances is advised.
func WithDefaultP ¶
func WithDefaultP(p float64) option
WithDefaultP allows defining the default error probability when tempting fate.
func WithOfficeHours ¶
WithOfficeHours allows limiting errors to office hours.
func WithPackageP ¶
WithPackageP allows defining the per package error probability when tempting fate.
func WithoutOfficeHours ¶
func WithoutOfficeHours() option
WithoutOfficeHours allows disabling limiting of errors to office hours.