fault

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fault defines the fault primitives that rules execute when they fire. Each fault implements Apply(ctx); a non-nil error short-circuits the adapter's Action.Before chain and is delivered to the caller in the adapter's native error model.

Index

Constants

This section is empty.

Variables

View Source
var ErrConnDrop = errors.New("chaotic: connection drop")

ErrConnDrop is the sentinel returned by ConnDrop's Apply. Each adapter detects this sentinel via errors.Is and substitutes its native connection-drop error (driver.ErrBadConn, status.Unavailable, etc.).

Functions

This section is empty.

Types

type Fault

type Fault interface {
	Apply(ctx context.Context) error
}

Fault is one chaos primitive. Apply may sleep, return an error, or panic. A return of nil means the fault completed without affecting the call.

func ConnDrop

func ConnDrop() Fault

ConnDrop returns ErrConnDrop. Each adapter detects this sentinel and substitutes its native connection-drop error.

func Error

func Error(err error) Fault

Error returns err verbatim from Apply. The adapter is responsible for wrapping it into its native error model (e.g., &url.Error{Op: "chaos"} for http). A nil err makes Apply a no-op.

func Jittered

func Jittered(min, max time.Duration) Fault

Jittered sleeps for a uniformly random duration in [min, max]. Negative or zero values are treated as "no sleep". If max <= min, sleeps for min.

func Latency

func Latency(d time.Duration) Fault

Latency sleeps for d. Returns ctx.Err() if the context is canceled first. A non-positive d returns immediately.

func Panic

func Panic(v any) Fault

Panic calls panic(v) from Apply. The panic propagates through the action, through the adapter, out to the caller. Recovery is the caller's responsibility.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL