All Products
Search
Document Center

CloudFlow:Fail

Last Updated:Dec 11, 2023

This topic describes Fail states and provides related examples.

Overview

A Fail state is used to terminate a series of states before the series of states are executed. A Fail state is similar to actions such as raise and throw in programming languages. In the typical definition of a flow, the next state is executed after the current state is complete. However, if the current state is a Fail state, the next state is not executed. If a flow proceeds to the Fail state, all states in the scope are terminated. In this case, the entire flow is terminated.

The following table describes the attributes that a Fail state contains.

Attribute

Type

Required

Description

Example

Name

string

Yes

The name of the state.

my state

Description

string

No

The description of the state.

describe it here

Type

string

Yes

The type of the state.

Fail

InputConstructor

map[string]any

No

The input constructor.

See InputConstructor.

OutputConstructor

map[string]any

No

The output constructor.

See OutputConstructor.

Code

string

No

The error code that is returned.

customBizCode

Detail

string

Yes

The description of the error.

my custom error

You must define a custom error for the Fail state. If the custom error occurs, the flow fails and ends. In a Succeed state, the flow to which the Succeed state belongs ends after the current scope is complete. You can use the Code parameter to specify the error code and use the Detail parameter to specify additional details.

Example

The following sample flow uses a Fail state to terminate a scope.

Type: StateMachine
Name: my-workflow
SpecVersion: v1
Description: " "
StartAt: Choice1
States:
  - Type: Choice
    Name: Choice1
    Branches:
      - Condition: $Input.status == "true"
        Next: Pass1
    Default: Fail1
  - Type: Fail
    Name: Fail1
    Code: "customBizCode"
    End: true
  - Type: Pass
    Name: Pass1
    End: true

A Fail state can be considered as a Pass state whose End attribute is true and that returns an error.

In this example, if the $Input.status=="true" condition is not met, the flow proceeds to the default state and the entire flow is terminated.