Error handling (onError) reference
This page lists every field and option. The overview shows what it does and a first example.
onError sets what happens when a resource fails: retry, use a fallback value, or log and continue. Without it, any error stops the workflow.
Set per resource.
Complete reference
# resources/example.yaml
onError:
action: continue # "continue" (use fallback), "retry", or "fail" (default)
maxRetries: 3 # for action: retry -- total attempts after the first
retryDelay: "1s" # wait between retries
fallback: # for action: continue -- what get('resourceId') returns on failure
status: "error"
message: "Service unavailable"
expr: # expressions that run when an error is caught
- set('errorMessage', error.message)
- set('errorLogged', true)
when: # only apply onError if one of these is true
- error.type == 'TIMEOUT' # otherwise the error propagates normally
- error.message contains 'connection refused'| action | what happens |
|---|---|
continue | downstream resources run; get('resourceId') returns the fallback |
fail | workflow stops and returns the error (default when no onError block) |
retry | resource is retried up to maxRetries times; fails after that |
Basic usage
Continue with fallback
Continue execution even if the resource fails, using a fallback value:
# resources/fetch-data.yaml
actionId: fetchData
component:
name: http_request
with:
url: "https://api.example.com/data"
method: GET
flow:
onError:
action: continue
fallback:
data: []
fromCache: false
error: trueWhen the HTTP request fails, the resource returns the fallback value. The workflow does not stop.
Continue without fallback
If you give no fallback, the resource returns an error info object:
# resources/example.yaml
onError:
action: continueOutput:
{
"_error": {
"message": "connection refused",
"handled": true
}
}Retry with backoff
Retry failed operations:
# resources/unreliable-api.yaml
actionId: unreliableApi
component:
name: http_request
with:
url: "https://flaky-api.example.com/data"
method: GET
flow:
onError:
action: retry
maxRetries: 3
retryDelay: "1s"Steps:
- Execute the resource
- On failure, wait 1 second
- Retry up to 3 times total
- If all retries fail, return an error
Explicit fail
State explicitly that errors stop execution:
# resources/example.yaml
onError:
action: failThis is the default behavior when you do not configure onError.
Advanced usage
Error-specific handling with when
Handle only specific types of errors:
# resources/example.yaml
onError:
action: continue
fallback:
status: "timeout"
when:
- error.type == 'TIMEOUT'
- error.message contains 'deadline exceeded'If the error does not match any when condition, the error is NOT handled and propagates normally.
Execute expressions on error (expr)
Run expressions on error, e.g. for logging or metrics:
# resources/example.yaml
onError:
action: continue
expr:
- set('lastError', error.message, 'session')
- set('errorCount', get('errorCount', 'session') + 1, 'session')
- set('errorTimestamp', info('timestamp'))
fallback:
error: true
retryLater: trueThe expressions have access to the error object:
error.message- The error message stringerror.type- Error type/code (e.g., "TIMEOUT", "VALIDATION_ERROR")error.code- Error code (same as type)error.statusCode- HTTP status code (if applicable)error.details- More error details (if available)
Dynamic fallback values
Fallback values can include expressions:
# resources/example.yaml
onError:
action: continue
fallback:
data: "{{ get('cachedData', 'session') }}"
timestamp: "{{ info('timestamp') }}"
error: trueUse cases
Resilient API calls
# resources/fetch-user-data.yaml
actionId: fetchUserData
component:
name: http_request
with:
url: "https://api.example.com/users/{{ get('userId') }}"
method: GET
timeout: 5s
flow:
onError:
action: retry
maxRetries: 3
retryDelay: "500ms"Graceful degradation
# resources/llm-enhancement.yaml
actionId: llmEnhancement
chat:
context:
prompt: "Enhance this text: {{ get('text') }}"
flow:
onError:
action: continue
fallback: "{{ get('text') }}" # Return original text on failureCircuit breaker pattern
# resources/external-service.yaml
actionId: externalService
# Check circuit breaker state first
validations:
skip:
- get('circuitOpen', 'session') == true
component:
name: http_request
with:
url: "https://api.example.com/data"
method: GET
flow:
onError:
action: continue
expr:
# Increment failure count
- set('failCount', default(get('failCount', 'session'), 0) + 1, 'session')
# Open circuit after 5 failures
- set('circuitOpen', get('failCount', 'session') >= 5, 'session')
fallback:
error: true
circuitBreaker: "open"Database fallback
# resources/query-primary.yaml
actionId: queryPrimary
component:
name: sql
with:
connectionName: primary
query: "SELECT * FROM users WHERE id = ?"
params:
- "{{ get('userId') }}"
flow:
onError:
action: continue
fallback: null
---
actionId: queryReplica
flow:
requires:
- queryPrimary
# Only query replica if primary failed
validations:
skip:
- get('queryPrimary') != null
- safe(get('queryPrimary'), '_error') == nil
component:
name: sql
with:
connectionName: replica
query: "SELECT * FROM users WHERE id = ?"
params:
- "{{ get('userId') }}"LLM with model fallback
# resources/primary-l-l-m.yaml
actionId: primaryLLM
chat:
context:
prompt: "{{ get('q') }}"
flow:
onError:
action: continue
fallback: null
---
actionId: fallbackLLM
flow:
requires:
- primaryLLM
validations:
skip:
- get('primaryLLM') != null
- safe(get('primaryLLM'), '_error') == nil
chat:
context:
prompt: "{{ get('q') }}"
---
actionId: response
flow:
requires:
- primaryLLM
- fallbackLLM
apiResponse:
success: true
response:
answer: "{{ default(get('primaryLLM'), get('fallbackLLM')) }}"Error object reference
In onError.expr and onError.when expressions, the error object is available:
| Property | Type | Description |
|---|---|---|
error.message | string | Human-readable error message |
error.type | string | Error type code |
error.code | string | Same as type |
error.statusCode | number | HTTP status code (if applicable) |
error.details | object | Additional error context |
Common error types
| Type | Description |
|---|---|
execution_error | General execution failure |
TIMEOUT | Request timed out |
VALIDATION_ERROR | Input validation failed |
NOT_FOUND | Resource not found |
UNAUTHORIZED | Authentication required |
RESOURCE_FAILED | Resource execution failed |
Best practices
- Use retries for transient failures - Network issues, rate limits, temporary unavailability
- Use continue for non-critical operations - Enhancements, optional data, caching
- Use when conditions - Handle specific errors differently
- Log errors with expr - Store error info for debugging/monitoring
- Provide meaningful fallbacks - Return useful data even on failure
- Combine with validations.skip - Create fallback resource chains
See also
- Validation and control flow - Input validation
- Expression helpers - Helper functions
- Resources overview - Resource types
