Allow your flow to continue to operate despite errors.
There are multiple ways to handle errors in Kestra, to both help you identify them and allow flows to continue to operate despite errors.
errors
Component
errors
is a list of tasks set at the flow level that will be executed when an error occurs. You can add multiple tasks, and they will be executed sequentially. This is useful for sending alerts when errors occur.
The example below sends a flow-level failure alert via Slack using the SlackIncomingWebhook task defined using the errors
property.
id: errors
namespace: company.team
description: This will always fail
tasks:
- id: failed_task
type: io.kestra.plugin.core.execution.Fail
errors:
- id: alert_on_failure
type: io.kestra.plugin.notifications.slack.SlackIncomingWebhook
url: secret('SLACK_WEBHOOK')
payload: |
{
"channel": "#alerts",
"text": "Failure alert for flow {{ flow.namespace }}.{{ flow.id }} with ID {{ execution.id }}"
}
Two kinds of error handlers can be defined:
- Global: error handling global to a flow that must be at the root of the flow.
- Local: error handling local to a Flowable Task, will handle errors for the flowable task and its children.
Global Error Handler
This flow example has a single task that fails immediately.
The global error handler will then be called so the 2nd
task will run.
id: errors
namespace: company.team
tasks:
- id: failed
type: io.kestra.plugin.core.execution.Fail
errors:
- id: 2nd
type: io.kestra.plugin.core.log.Log
message: I'm failing {{task.id}}
level: INFO
Local Error Handler
In this flow example, the error branch will be used only if a child of the task t2
has an error. If the task t1
failed, the error branch would not be used.
This can be useful to restrict error handling for a specific part of the flow and perform specific tasks like resource cleanup.
id: errors
namespace: company.team
tasks:
- id: parent-seq
type: io.kestra.plugin.core.flow.Sequential
tasks:
- id: t1
type: io.kestra.plugin.core.debug.Return
format: "{{task.id}} > {{taskrun.startDate}}"
- id: t2
type: io.kestra.plugin.core.flow.Sequential
tasks:
- id: t2-t1
type: io.kestra.plugin.core.execution.Fail
errors:
- id: error-t1
type: io.kestra.plugin.core.debug.Return
format: "Error Trigger ! {{task.id}}"
allowFailure
Property
When you execute a flow and one of its tasks fails, downstream tasks won't be executed. This may not always be desirable, especially for non-critical tasks. You can resolve this by adding the allowFailure
property to the task, which will allow downstream tasks to continue despite the error. In this case, the execution will end in a WARNING
state.
id: allow_failure
namespace: company.team
description: This flow will allow a failure of a task (imagine a flaky unit test) and will continue processing the last task, leaving the execution in a `WARNING` state.
tasks:
- id: first
type: io.kestra.plugin.core.debug.Return
format: "{{task.id}} > {{taskrun.startDate}}"
- id: allow_failure
type: io.kestra.plugin.scripts.shell.Commands
taskRunner:
type: io.kestra.plugin.core.runner.Process
allowFailure: true
commands:
- exit 1
- id: last
type: io.kestra.plugin.core.debug.Return
format: "{{task.id}} > {{taskrun.startDate}}"
Was this page helpful?