Error Handling in batch
Commands
Introduction
When executing batch
commands in Coordinator, understanding error handling is crucial for building robust and resilient sequences. By default, if any step in a batch
encounters an error, the entire batch
execution will stop. However, batch
provides a mechanism to allow certain steps to continue execution even if they encounter errors. This is achieved through the use of the allowFailure
keyword.
Basic Error Handling
In a typical batch
command execution, if any step encounters an error, the entire batch
execution is halted. This ensures that issues are addressed before moving on to subsequent steps. Consider the following example:
version: 1
steps:
- description: Step 1 - Successful Operation
action: test.run
args:
target: qa
script: test_script_1.js
- description: Step 2 - Failing Operation
action: test.run
args:
target: qa
script: test_script_2.js # This script contains an intentional error
In this example, if "Step 1" is successful but "Step 2" encounters an error, the entire batch
execution will be stopped.
Introducing allowFailure
Keyword
To allow specific steps to continue execution even if they encounter errors, you can use the allowFailure
keyword. This keyword is applied at the step level in the recipe, indicating that the batch
should proceed to the next step regardless of the success or failure of the current step.
Consider the following modified example:
version: 1
steps:
- description: Step 1 - Successful Operation
action: test.run
args:
target: qa
script: test_script_1.js
- description: Step 2 - Ignoring Failure
action: test.run
args:
target: qa
script: test_script_2.js # This script contains an intentional error
allowFailure: true
- description: Step 3 - Subsequent Operation
action: test.run
args:
target: qa
script: test_script_3.js
In this example, even if "Step 2" encounters an error, the allowFailure
keyword allows the batch
to continue to "Step 3."