fault

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 5 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 JitteredSeed added in v1.4.0

func JitteredSeed(min, max time.Duration, seed int64) Fault

JitteredSeed is like Jittered but draws from a seeded PCG source, so the sequence of sleep durations is reproducible across runs with the same seed. Use it when a chaos test must be deterministically replayable. The draw is mutex-guarded. The fault is safe for concurrent use.

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.

type Kind added in v1.4.0

type Kind int

Kind classifies a Fault for introspection (linting, observability). It does not affect behavior.

const (
	KindUnknown Kind = iota
	KindLatency
	KindJittered
	KindError
	KindPanic
	KindConnDrop
)

Fault kinds, one per built-in fault type.

func KindOf added in v1.4.0

func KindOf(f Fault) Kind

KindOf returns f's Kind, or KindUnknown for a custom fault that does not implement Kinded.

type Kinded added in v1.4.0

type Kinded interface {
	Kind() Kind
}

Kinded is implemented by every built-in fault so tools can classify it without type-switching on unexported types.

Jump to

Keyboard shortcuts

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