Fail step

更新时间:
复制 MD 格式

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 status in the input is ready, the flow executes the pass1 step in the first choice branch, and then executes the final step.
  • If the value of status in the input is failed, the flow follows the `goto` instruction in the second choice branch and executes the handle_failure step. Because handle_failure is a fail step, the flow does not execute the final step after handle_failure
  • If the input does not contain status, or if the value of status is not ready or failed, the flow executes the default steps, pass2 and handle_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