In Qntrl Circuit, you can configure error handling while building a circuit. State definition errors are detected even before saving the circuit. When you save the circuit, a compilation check runs and lists out errors related to its state configurations, logic flow, and design. This helps you verify and fix errors in your circuit design and configuration even before execution.
Only Functional states, such as Function, Webhook, and Circuit, are subject to runtime errors, so the error handling is supported only for Functional states. When you add a functional state, the Error Handling option appears under Configuration in the right panel.
Runtime Error Scenarios
Runtime errors are categorized into four scenarios, each with Retry and Fallback error handling options.
On Timeout
On Authorization Failure
On Execution Failure
Custom Error
On Timeout
When a functional state runs longer than the expected time, a timeout error occurs. This option is available for Function and Webhook. For handling timeout errors in Code View, the field value "errorType": "Error.TimeOut" will be added.
On Authorization Failure
If a state fails because of insufficient privileges to access the specified code, the error is handled as an authorization failure. This option is only available for Webhook states. In the code view, the name value "errorType": "Error.AuthorizationFailure" is added.
On Execution Failure
When a state execution fails due to some exception that cannot be processed, it can be handled using execution failure. In code view, the name value "errorType": "Error.ExecutionFailure" is appended.
Custom Error
Handle exceptions in your function through an Error Code or an Error Message besides Retry and Fallback options. Refer Custom Error section to configure custom error.
Error Handling Options
When you select any error handling options, a pop-up appears with Retry and Fallback fields common for all error-handling options.
Retry
You can retry the failed state for a specific number of attempts within predefined intervals.
Retry consists of three fields:
Delay: Set the time in seconds after which the state must be retried after failure.
Attempt: Set the number of retry attempts.
Step Delay: Increase the delay time for each attempt by multiplying the delay time with the Step Delay number set.
For example, if Delay is set to 5 seconds, Attempt to 3, and Step Delay to 2:
New Delay Time = Delay * Step Delay ^ (attempt - 1)
1st attempt --> 5s * (2^0) = 5s
2nd attempt --> 5s * (2^1) = 10s
3rd attempt --> 5s * (2^2) = 20s
The first retry attempt takes place after 5 seconds, the second attempt takes 10 seconds, and the third attempt takes 20 seconds to execute.
Fallback
In case of failure or error, the failed state can fall back to another state to continue the execution. For setting up Fallback, configure the following two fields:
Next: Set the state name to which the inputs of the failed state and error output have to be passed.
Result: Set the field name from which the error details can be retrieved.
Error Path: Maps error responses in case of failure, specifying the input for the next state.
Error Selector: Configures error responses that can be merged with the previous state input and transitioned to the Fallback state.
Custom Error
For custom error handling, you need to configure Exception Type and Exception Value.
Click the +Add Custom Error option under Error Handling. A pop up appears.
Under Exceptions, select Error Code/Error Message from the dropdown using which the error handling must take place.
In the next field enter the path/value where the error code or error message will be received in the state output.
By default, the Custom Error name is set to Error 1, Error 2 or Error 3 based on the number of custom errors configured. To change the default name, click the 'edit' icon and specify a name.
For custom errors in Code View, the name value "errorType": "Error.Custom" is appended. A sample state that handles an On Timeout and Custom Error in code view is displayed below.
{
"Function for stock status": {
"type": "function",
"next": "End",
"start": true,
"function_id": "updatestockstatus_71",
"on_error": [
{
"error_type": "timeout_error",
"retry": {
"delay": 3,
"attempt": 3,
"step_delay": 1
},
"fallback": {
"next": "End",
"error_path": "$.error3"
}
},
{
"error_type": "custom_error",
"error_name": "Error 1",
"error_code": "101",
"retry": {
"delay": 3,
"attempt": 3,
"step_delay": 1
},
"fallback": {
"next": "End",
"error_path": "$.Error"
}
}
]
}
}