What would you like to be added?
Support for the then directive (or a similar control-flow transition) directly within the catch clause of a try task in the Serverless Workflow DSL.
Proposal(s):
I propose adding a then property to the catch object definition. When an execution error is caught by matching the errors criteria, the workflow should immediately transition to the task specified by the then directive, bypassing the default sequential flow.
Here is an example of how this would look in the DSL:
document:
dsl: '1.0.3'
namespace: test
name: try-example
version: '0.1.0'
do:
- trySomething:
try:
- invalidHttpCall:
call: http
with:
method: get
endpoint: https://
catch:
errors:
with:
type: https://serverlessworkflow.io/dsl/errors/types/communication
status: 503
then: sharedErrorHandlerTask # <-- Transitions to a reusable task defined elsewhere
Alternative(s):
-
Using a subsequent switch task: Catching the error, mapping it to a state variable, and following the try task with a switch statement to evaluate the error variable and branch accordingly. However, this is much more verbose, spreads the error-handling logic across multiple tasks, and hurts readability.
-
Using the do directive within catch: We can currently define tasks inline using do. However, if multiple tasks across the workflow need to trigger the same compensation or error-handling sequence, using do forces us to duplicate that logic inline every single time, violating DRY principles.
Additional info:
The primary motivation for this addition is task reusability and control flow flexibility.
Currently, if we want to handle an error, we are forced to define the reaction inline (via do). However, in complex workflows or Saga patterns, it is common for multiple different tasks to fail in ways that require the exact same compensation sequence (e.g., a shared rollbackTransaction or notifyAdmin task).
By introducing the then directive into the catch clause, we can transition the control flow to a task that is called by another control flow or sits in the default control flow of the same workflow. This allows multiple try tasks to cleanly route to a single, shared error-handling task, significantly reducing duplication and making the workflow much easier to maintain.
Community Notes
- Please vote by adding a 👍 reaction to the feature to help us prioritize.
- If you are interested to work on this feature, please leave a comment.
What would you like to be added?
Support for the
thendirective (or a similar control-flow transition) directly within thecatchclause of atrytask in the Serverless Workflow DSL.Proposal(s):
I propose adding a
thenproperty to thecatchobject definition. When an execution error is caught by matching the errors criteria, the workflow should immediately transition to the task specified by thethendirective, bypassing the default sequential flow.Here is an example of how this would look in the DSL:
Alternative(s):
Using a subsequent switch task: Catching the error, mapping it to a state variable, and following the
trytask with aswitchstatement to evaluate the error variable and branch accordingly. However, this is much more verbose, spreads the error-handling logic across multiple tasks, and hurts readability.Using the do directive within catch: We can currently define tasks inline using
do. However, if multiple tasks across the workflow need to trigger the same compensation or error-handling sequence, usingdoforces us to duplicate that logic inline every single time, violating DRY principles.Additional info:
The primary motivation for this addition is task reusability and control flow flexibility.
Currently, if we want to handle an
error, we are forced to define the reaction inline (via do). However, in complex workflows or Saga patterns, it is common for multiple different tasks to fail in ways that require the exact same compensation sequence (e.g., a sharedrollbackTransactionornotifyAdmintask).By introducing the
thendirective into thecatchclause, we can transition the control flow to ataskthat is called by another control flow or sits in the default control flow of the same workflow. This allows multipletrytasks to cleanly route to a single, shared error-handling task, significantly reducing duplication and making the workflow much easier to maintain.Community Notes