Skip to content

Error Handling

Retry, fallback, and circuit breaker patterns.

3 modules

ModuleDescription
Circuit BreakerProtect against cascading failures with circuit breaker pattern
FallbackProvide fallback value when operation fails
RetryWrap operations with configurable retry logic

Modules

Circuit Breaker

error.circuit_breaker

Protect against cascading failures with circuit breaker pattern

Parameters:

NameTypeRequiredDefaultDescription
actionobjectYes-The action to protect with circuit breaker
circuit_idstringYes-The action to protect with circuit breaker
failure_thresholdnumberNo5Unique identifier for this circuit (for state tracking)
failure_window_msnumberNo60000Time window for counting failures
recovery_timeout_msnumberNo30000Time before attempting recovery (half-open state)
success_thresholdnumberNo3Successful requests needed in half-open to close circuit
fallbackobjectNo-Alternative action when circuit is open
fallback_valueanyNo-Alternative action when circuit is open
track_errorsarrayNo[]Static value to return when circuit is open

Output:

FieldTypeDescription
__event__stringOnly count these error codes toward threshold (empty = all)
resultanyEvent for routing (success/circuit_open/fallback)
circuit_statestringResult from action or fallback
failure_countnumberCurrent state of circuit (closed/open/half_open)
last_failure_timestringCurrent failure count in window
circuit_opened_atstringTimestamp of last failure

Example: Example

yaml
action: {"module": "http.post", "params": {"url": "https://api.example.com/submit"}}
circuit_id: example-api
failure_threshold: 5
failure_window_ms: 60000
recovery_timeout_ms: 30000

Example: Example

yaml
action: {"module": "http.get", "params": {"url": "https://api.example.com/data"}}
circuit_id: data-api
failure_threshold: 3
fallback: {"module": "cache.get", "params": {"key": "data_cache"}}

Example: Example

yaml
action: {"module": "database.query", "params": {"query": "SELECT * FROM users"}}
circuit_id: database
failure_threshold: 3
fallback_value: {"users": [], "from_cache": false}

Fallback

error.fallback

Provide fallback value when operation fails

Parameters:

NameTypeRequiredDefaultDescription
operationobjectNo-The primary operation to attempt
fallback_valueanyNo-The primary operation to attempt
fallback_operationobjectNo-Static value to return on failure
fallback_onarrayNo[]Alternative operation to execute on failure
include_error_infobooleanNoTrueError codes that trigger fallback (empty = all errors)
log_fallbackbooleanNoTrueInclude original error information in output

Output:

FieldTypeDescription
resultanyLog when fallback is used
used_fallbackbooleanResult from primary operation or fallback
sourcestringWhether fallback was used
original_errorobjectSource of result (primary/fallback_value/fallback_operation)

Example: Example

yaml
operation: {"module": "http.get", "params": {"url": "https://api.example.com/items"}}
fallback_value: []

Example: Example

yaml
operation: {"module": "http.get", "params": {"url": "https://api.example.com/config"}}
fallback_operation: {"module": "cache.get", "params": {"key": "config_cache"}}

Example: Example

yaml
operation: {"module": "api.call", "params": {"endpoint": "/data"}}
fallback_value: {"status": "unavailable"}
fallback_on: ["NETWORK_ERROR", "TIMEOUT_ERROR"]

Retry

error.retry

Wrap operations with configurable retry logic

Parameters:

NameTypeRequiredDefaultDescription
operationobjectYes-The operation to retry (module ID and params)
max_retriesnumberNo3The operation to retry (module ID and params)
initial_delay_msnumberNo1000Maximum number of retry attempts
max_delay_msnumberNo30000Initial delay before first retry
backoff_multipliernumberNo2.0Multiplier for exponential backoff (e.g., 2 doubles delay each retry)
jitterbooleanNoTrueAdd random jitter to delay to prevent thundering herd
retry_onarrayNo[]Add random jitter to delay to prevent thundering herd
timeout_per_attempt_msnumberNo0List of error codes to retry on (empty = retry all)

Output:

FieldTypeDescription
__event__stringTimeout for each attempt (0 for no timeout)
resultanyEvent for routing (success/exhausted)
attemptsnumberEvent for routing (success/exhausted)
total_delay_msnumberResult from successful attempt
errorsarrayNumber of attempts made

Example: Example

yaml
operation: {"module": "http.get", "params": {"url": "https://api.example.com/data"}}
max_retries: 3

Example: Example

yaml
operation: {"module": "database.query", "params": {"query": "SELECT * FROM users"}}
max_retries: 5
initial_delay_ms: 2000
backoff_multiplier: 2.0
jitter: true

Example: Example

yaml
operation: {"module": "api.call", "params": {"endpoint": "/submit"}}
max_retries: 3
retry_on: ["NETWORK_ERROR", "TIMEOUT_ERROR", "SERVICE_UNAVAILABLE"]

Released under the Apache 2.0 License.