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.

yaml
id: errors
namespace: company.team

description: This will always fail

tasks:
  - id: failed_task
    type: io.kestra.plugin.scripts.shell.Commands
    taskRunner: 
      type: io.kestra.plugin.core.runner.Process
    commands:
      - "exit 1"

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 }}"
      }

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.

yaml
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?