This topic describes the fail step and provides examples of its usage.
Introduction
A fail step ends a sequence of steps early. It is similar to operations such as raise or throw in programming languages. When a flow executes a fail step, subsequent steps are not executed. The fail step causes its parent step to fail. This failure propagates upward, which ultimately causes the entire flow to fail.
A fail step has the following properties:
- (Required) type: The type of the step. The value must be `fail`.
- (Required) name: The name of the step.
- (Optional) error: The type of the fault.
- (Optional) cause: The reason for the fault.
- (Optional) inputMappings: The input mappings.
- (Optional) outputMappings: The output mappings.
Example
The following flow definition uses a fail step to end the flow execution prematurely.
- If the value of
statusin the input isready, the flow executes thepass1step in the first choice branch, and then executes thefinalstep. - If the value of
statusin the input isfailed, the flow follows the `goto` instruction in the second choice branch and executes thehandle_failurestep. Becausehandle_failureis a fail step, the flow does not execute thefinalstep afterhandle_failure - If the input does not contain
status, or if the value ofstatusis notreadyorfailed, the flow executes the default steps,pass2andhandle_failure.
version: v1
type: flow
steps:
- type: choice
name: mychoice
choices:
- condition: $.status == "ready"
# choice with steps
steps:
- type: pass
name: pass1
goto: final
- condition: $.status == "failed"
goto: handle_failure
default:
# no need to use goto
steps:
- type: pass
name: pass2
- type: fail
name: handle_failure
error: StatusIsNotReady
cause: status is not ready
- type: pass
name: final 该文章对您有帮助吗?