Error Handling
When a task fails, you need a way to run cleanup logic, send notifications, or trigger compensating actions. Both durable tasks and DAGs support error handling, but the mechanism differs: durable tasks use standard try/catch blocks, while DAGs declare a special on-failure task.
Try/Catch in Durable Tasks
Durable tasks are regular functions, so you handle errors with your language’s native error handling (try/except in Python, try/catch in TypeScript/Go). This gives you full control over what happens when a child task or operation fails.
Handling child task errors
When spawning child tasks, wrap the call in a try/catch block to handle failures gracefully:
Common patterns
- Retry with backoff — Catch the error, sleep, and retry the child task.
- Fallback logic — If a primary path fails, spawn a different child task as a fallback.
- Partial failure handling — In a fan-out, collect results from successful children and handle failures individually rather than failing the entire workflow.
- Cleanup — Release resources, cancel in-progress work, or notify external systems.