CloudFlow workflows can encounter expected or unexpected errors during execution. Error handling lets you recover gracefully by retrying the failed state or transitioning to a different state.
Two mechanisms work together:
Retry -- Automatically re-executes the failed state. Use this for transient errors such as throttling or temporary network issues.
Catch -- Transitions the workflow to a designated state when an error persists after all retries are exhausted.
CloudFlow always evaluates Retry first. Only after all retry attempts fail does it evaluate Catch.
Supported states
Add Retry and Catch fields to the following state types:
Retry
The Retry field accepts an array of retry rules. Each rule specifies which errors to match and how to retry.
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
Errors | []string | Yes | Error types to match. See Error types. | ["MyCustomError", "FnF.ALL"] |
Description | string | Yes | A label for this retry rule. | Retry policy #1 |
MaxAttempts | int | Yes | Maximum number of retry attempts. | 3 |
IntervalSeconds | int | Yes | Initial interval between retries, in seconds. Maximum: 86,400 (24 hours). | 10 |
BackoffRate | float | No | Multiplier applied to IntervalSeconds after each attempt. When omitted, the interval stays constant. | 2 |
MaxBackoffSeconds | int | No | Upper bound for the computed retry interval, in seconds. Maximum: 86,400 (24 hours). | 30 |
If multiple retry rules match the same error type, CloudFlow uses the first matching rule only. Place more specific error types before FnF.ALL so they are evaluated first.
Catch
The Catch field accepts an array of catch rules. When an error persists after all retries, CloudFlow evaluates catch rules in order and transitions to the Next state of the first matching rule.
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
Errors | []string | Yes | Error types to match. See Error types. | ["MyCustomException1", "FnF.ALL"] |
Description | string | Yes | A label for this catch rule. | Error catch rule #1 |
OutputConstructor | map[string]any | No | Constructs custom output to pass as input to the Next state. See State OutputConstructor. | See examples below. |
Next | string | Yes | The state to transition to when the error is caught. | my-next-state |
OutputConstructor
When an error occurs, the failed state produces no output. Without OutputConstructor, the next state receives no input and the workflow cannot proceed meaningfully. Use OutputConstructor to build a structured output that the Next state can consume.
If multiple catch rules match the same error type, CloudFlow uses the first matching rule only.
Error types
CloudFlow errors
These errors originate from the CloudFlow engine itself.
| Error type | Description |
|---|---|
FnF.TaskTimeout | A single step in the workflow timed out. |
FnF.Timeout | The overall execution of a workflow timed out. |
FnF.ALL | A wildcard that catches all errors of CloudFlow. Place this as the last entry in your Retry or Catch array so that more specific rules are evaluated first. |
Function Compute errors
These errors occur when CloudFlow invokes Function Compute. For error types related to other service integrations, see the corresponding service documentation.
| Error type | Description |
|---|---|
FC.ResourceThrottled | Functions throttled due to high concurrency. All functions are limited by a total concurrency value. CloudFlow synchronously invokes Function Compute when CloudFlow executes Task states. The total concurrency value is the sum of the concurrency value in function invocations and the concurrency values of other invocation methods. You can request to modify the concurrency value of synchronous Function Compute invocations. |
FC.ResourceExhausted | Functions throttled due to insufficient resources. Contact us to resolve this. |
FC.InternalServerError | A system error in Function Compute. Re-execute the workflow. |
FC.Unknown | Function Compute invoked the function, but an uncaught error occurred during execution. Sample error code: UnhandledInvocationError. |
FC.{ErrorCode} | Any other Function Compute error where {ErrorCode} is the specific error code. See Function Compute error codes. |
Custom errors
| Error type | Description |
|---|---|
{CustomError} | Custom exception errors thrown by the callee, such as business logic errors in your functions. |
Examples
All examples use a Task state that invokes a Function Compute function via FC:InvokeFunction. Replace the resourceArn placeholder with your actual function ARN:
acs:fc:<region-id>:<account-id>:functions/<function-name>/<version-or-alias>| Placeholder | Description | Example |
|---|---|---|
<region-id> | Region where the function resides | cn-hangzhou |
<account-id> | Alibaba Cloud account ID | Your numeric account ID |
<function-name> | Function name | myfunction |
<version-or-alias> | Function version or alias | LATEST |
For details on obtaining the function ARN, see Obtain the ARN of the function.
Basic retry and catch
This example retries MyCustomException1 up to 3 times at 2-second intervals. If all retries fail, the catch rule constructs custom error output and transitions to ErrorCatchExit.
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: acs:fc:{regionId}:{accountId}:functions/myfunction/LATEST
invocationType: Sync
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: trueWhat happens at runtime:
The Task state runs
FC:InvokeFunction.If
MyCustomException1occurs, CloudFlow retries up to 3 times, waiting 2 seconds between attempts.If all retries fail, the catch rule matches
MyCustomException1, constructs output withErrorCodeandErrorMessage, and transitions toErrorCatchExit.If no error occurs, the workflow transitions to
SucceededExit.
MyCustomException1 is used as an example. You can modify the error name based on your business requirements.
Backoff retry
This example retries MyCustomException2 or MyCustomException3 up to 3 times with exponential backoff. The initial interval is 5 seconds and doubles after each attempt (backoff rate 2.0).
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: acs:fc:{regionId}:{accountId}:functions/myfunction/LATEST
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: trueRetry timing:
The system attempts retries at intervals of 5, 10, 20, and 40 seconds based on the backoff rate 2.0.
If all retries fail, the catch rule transitions the workflow to ErrorCatchExit. No OutputConstructor is defined here, so the next state receives no custom error output.
Multiple retry and catch policies
This example combines three levels of error handling with different retry strategies:
MyCustomException1-- Retry up to 3 times at fixed 2-second intervals.MyCustomException2andMyCustomException3-- Retry up to 3 times with exponential backoff (initial: 5s, backoff rate: 2.0).FnF.ALL(catch-all) -- Retry up to 3 times with exponential backoff (initial: 5s, backoff rate: 2.0), capped at 30 seconds byMaxBackoffSeconds.
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: acs:fc:{regionId}:{accountId}:functions/myfunction/LATEST
body: xxx
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 3
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: trueHow rule matching works:
CloudFlow evaluates retry and catch rules in the order they appear. For an error that does not match MyCustomException1, MyCustomException2, or MyCustomException3, the FnF.ALL catch-all rule handles it. The FnF.ALL retry uses MaxBackoffSeconds: 30 to cap the interval, so the system attempts retries at intervals of 5, 10, 20, and 30 seconds.
After all retry attempts are exhausted, the corresponding catch rule transitions the workflow to ErrorCatchExit.