This topic describes the overview and examples of error handling during workflow integration.
Overview
Expected or unexpected errors may occur during the workflow integration of CloudFlow. You can retry the current state or move to the next state based on the scenario. The FnF.ALL
keyword is a special option that hits all errors. You can use the Retry and Catch fields to handle errors that occur during workflow integration.
The state that supports error handling
You can use the Retry and Catch fields in the definition of the following state to specify the retry and catch policies for errors that occur in the state.
CloudFlow always first executes the Retry policy when handling errors. If the Retry policy fails, CloudFlow executes the Catch policy.
Retry
Parameter | Type | Required | Description | Example |
Errors | []string | Yes | Errors that can be hit. For more information, see Common error types. | -MyCustomError -FnF.ALL |
Description | string | No | The description of the retry policy. | An example of retry rules. |
MaxAttempts | int | Yes | The maximum number of retries. | 3 |
IntervalSeconds | int | Yes | The interval of retries. Maximum value: 86400. Unit: seconds. | 10 |
BackoffRate | float | No | The multiplier by which the retry interval specified by the IntervalSeconds parameter increases after each retry attempt. | 2 |
MaxBackoffSeconds | int | No | The maximum retry interval during the running of the workflow. Maximum value: 86400. Unit: seconds. | 30 |
If you define multiple retry rules for the same error type, CloudFlow only attempts retries based on the first matched retry rule.
Catch
Parameter | Type | Required | Description | Example |
Errors | []string | Yes | Errors that can be hit. For more information, see Common error types. | -MyCustomError -FnF.ALL |
Description | string | No | The description of the catch policy. | An example of catch rules. |
OutputConstructor | map[string]any | No | The output constructor. This parameter is used together with the Next parameter. | See OutputConstructor. |
Next | string | No | The state to which the workflow transits after a catch occurs. | my-next-state |
The OutputConstructor parameter is used together with the Next parameter. If an error occurs in a state, no expected outputs are generated in the state. The workflow cannot proceed even if the workflow transits to the next state. In this case, you can use the OutputConstructor parameter to construct an output and use the output as the input for the next state to which the workflow transits.
If you define multiple catch rules for the same error type, CloudFlow only performs catches based on the first matched catch rule.
Common error types
The following common error types occur when CloudFlow is integrated with Function Compute. For information about the error types that occur when CloudFlow is integrated with other cloud services, see the corresponding service integration documentation.
Error type | Description | |||
FC.{ErrorCode} | Function Compute returns HTTP status codes other than 200. Common error types:
Note
| |||
FC.Unknown | Function Compute invoked the function, but an error occurred during the function execution and was not caught. Sample error code: | |||
{CustomError} | The custom exception errors that are thrown by the callee, such as internal business errors of functions and CloudFlow. | |||
FnF.TaskTimeout | The execution of a step in a workflow times out. | |||
FnF.Timeout | The overall execution of a workflow times out. | |||
FnF.ALL | The system catches all errors of CloudFlow |
Examples of common error handling
Basic retries
In this example, if an error occurs and hits the MyCustomException1
retry policy during the service integration invocation named my-error-handle-example, the system attempts up to three retries based on the retry policy. After the three retry attempts are exhausted, the current error hits the MyCustomException1
catch policy. The system constructs a custom error output by using the OutputConstructor parameter and uses the custom error output as the input for the ErrorCatchExit
state. The flow transits to the ErrorCatchExit state.
Type: StateMachine
Name: ErrorHandleExample
SpecVersion: v1
Description: "an example of basic error handling"
StartAt: my-error-handle-example
States:
- Type: Task
Name: my-error-handle-example
Action: FC:InvokeFunction
TaskMode: RequestComplete
Parameters:
resourceArn: xxx
body: xxx
Retry:
- Errors:
- MyCustomException1
Description: retry policy 1
MaxAttempts: 3
IntervalSeconds: 2
Catch:
- Errors:
- MyCustomException1
Description: catch policy 1
OutputConstructor:
ErrorCode: MyCustomException1
ErrorMessage: MyCustomException1
Next: ErrorCatchExit
Next: SucceededExit
- Type: Pass
Name: ErrorCatchExit
End: true
- Type: Pass
Name: SucceededExit
End: true
Backoff retries
In this example, if an error occurs and hits the MyCustomException2
or MyCustomException3
retry policy during the service integration invocation named my-error-handle-example, the system attempts up to three retries based on the retry policy. The initial retry interval is 5 seconds. The system attempts retries at intervals of 5, 10, 20, and 40 seconds based on the backoff rate 2.0. After the three retry attempts are exhausted, the current error hits the MyCustomException2
or MyCustomException3
catch policy. The system constructs a custom error output by using the OutputConstructor parameter and uses the custom error output as the input for the ErrorCatchExit
state. The flow transits to the ErrorCatchExit state.
Type: StateMachine
Name: ErrorHandleExample
SpecVersion: v1
Description: "an example of backoff error handling"
StartAt: my-error-handle-example
States:
- Type: Task
Name: my-error-handle-example
Action: FC:InvokeFunction
TaskMode: RequestComplete
Parameters:
resourceArn: xxx
body: xxx
Retry:
- Errors:
- MyCustomException2
- MyCustomException3
Description: retry policy 2
MaxAttempts: 3
IntervalSeconds: 5
BackoffRate: 2.0
Catch:
- Errors:
- MyCustomException2
- MyCustomException3
Description: catch policy 2
Next: ErrorCatchExit
Next: SucceededExit
- Type: Pass
Name: ErrorCatchExit
End: true
- Type: Pass
Name: SucceededExit
End: true
Complex retry policies
In this example, a retry policy and a catch policy are specified for the FnF.ALL
error type. If an error other than MyCustomException1
, MyCustomException2
, and MyCustomException3
occurs during the service integration invocation named my-error-handle-example, the system attempts up to three retries based on the retry policy. The initial retry interval is 5 seconds. The last backoff interval based on a backoff rate of 2.0 is 40 seconds. However, the maximum backoff interval is set to 30 seconds. The system attempts retries at intervals of 5, 10, 20, and 30 seconds. After the three retry attempts are exhausted, the current error hits the FnF.ALL
catch policy. No custom error output is constructed by using the OutputConstructor parameter. By default, the flow transits to the ErrorCatchExit
state.
Type: StateMachine
Name: ErrorHandleExample
SpecVersion: v1
Description: "an example of error handling"
StartAt: my-error-handle-example
States:
- Type: Task
Name: my-error-handle-example
Action: FC:InvokeFunction
TaskMode: RequestComplete
Parameters:
resourceArn: xxx
body: xxx
Retry:
Retry:
- Errors:
- MyCustomException1
Description: retry policy 1
MaxAttempts: 3
IntervalSeconds: 2
- Errors:
- MyCustomException2
- MyCustomException3
Description: retry policy 2
MaxAttempts: 3
IntervalSeconds: 5
BackoffRate: 2.0
- Errors:
- FnF.ALL
Description: retry policy 2
MaxAttempts: 3
IntervalSeconds: 5
BackoffRate: 2.0
MaxBackoffSeconds: 30
Catch:
- Errors:
- MyCustomException1
Description: catch policy 1
OutputConstructor:
ErrorCode: MyCustomException1
ErrorMessage: MyCustomException1
Next: ErrorCatchExit
- Errors:
- MyCustomException2
- MyCustomException3
Description: catch policy 2
Next: ErrorCatchExit
- Errors:
- FnF.ALL
Description: catch policy 3
Next: ErrorCatchExit
Next: SucceededExit
- Type: Pass
Name: ErrorCatchExit
End: true
- Type: Pass
Name: SucceededExit
End: true