Serverless workflow integrates with multiple Alibaba Cloud services. When cloud services serve as execution nodes of task steps in Serverless workflow, configure retry and catch policies to handle execution errors and stabilize tasks in production.
Error handling methods
Task steps in Serverless workflow support error catching with retry or redirect actions. For more information, see Task steps.
- Retry a task after an error is caught.
steps: - type: task name: hello resourceArn: acs:fc:{region}:{accountID}:xxx retry: - errors: - FnF.ALL intervalSeconds: 10 maxIntervalSeconds: 300 maxAttempts: 3 multiplier: 2Table 1. Parameters for retrying a task after an error is caught Parameter Description retryRetries the task when an error is caught. errorsErrors to catch. intervalSecondsInitial retry interval in seconds. Maximum: 86400. Default: 1. maxAttemptsMaximum retry attempts. Default: 3. multiplierMultiplier applied to the retry interval after each attempt. Default: 2. In the sample code, the second retry runs after 20 seconds and the third after 40 seconds. - Redirect a task after an error is caught.
steps: - type: task name: hello resourceArn: acs:fc:{region}:{accountID}:xxx errorMappings: - target: errMsg source: $local.cause # This value is reserved for the system and can be directly used when an error occurs in this step. - target: errCode source: $local.error # This value is reserved for the system and can be directly used when an error occurs in this step. catch: - errors: - FnF.ALL goto: finalTable 2. Parameters for redirecting a task after an error is caught Parameter Description errorMappingsError fields from this step to pass during redirection. catchError catch policy for the task. errorsErrors to catch. gotoTarget step to redirect to when the task throws an error.
Function Compute errors in Serverless workflow
- Exceptions prompted by Function Compute
- Function code errors
errors in a task in Serverless workflow. Common system errors prompted by Function Compute or Serverless Workflow
- errors:
- FC.ResourceThrottled
- FC.ResourceExhausted
- FC.InternalServerError
- FC.Unknown
- FnF.TaskTimeout
- FnF.ALL
| Error type | Description |
FC.{ErrorCode} |
Function Compute returns a non-200 HTTP status code. Common types:
Note {Error code} is the Function Compute error code. For more information, see Error codes. |
FC.Unknown |
Function Compute invoked the function, but an uncaught error occurred during execution. Example: UnhandledInvocationError. |
{CustomError} |
Function Compute invoked the function, but the function threw an exception. |
FnF.TaskTimeout |
A step in Serverless workflow timed out. |
FnF.ALL |
Catches all errors in Serverless workflow. |
FnF.Timeout |
The overall flow execution in Serverless workflow timed out. |
Custom error types
- Define a custom error type in your function code.
... class ErrorNeedsRetry(Exception): pass def handler(event, context): try: # do sth except ServerException: raise ErrorNeedsRetry("custom error message") - Configure the task step in Serverless workflow to catch and retry the error.
retry: - errors: - ErrorNeedsRetry intervalSeconds: 10 maxAttempts: 3 multiplier: 2
Other cloud services as task execution nodes
When a third-party cloud service serves as a task execution node, Serverless workflow calls the service API directly to distribute the task.
For example, when MNS serves as the execution node, Serverless workflow calls the SendMessage operation to send messages. For more information, see SendMessage. These API-based tasks typically do not return execution results. After an error is caught, Serverless workflow retries up to the specified number of times. For services like MNS and Visual Intelligence API, you do not need to handle errors in the flow.