From de0c21934f5c53d4f0c629b76c4749780dd22bde Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Thu, 23 Jul 2026 15:08:09 -0400 Subject: [PATCH 1/4] [Fix #1148] Add then flow directive to catch clause Add support for the then flow directive in the catch clause of try tasks, enabling control flow transitions after catching errors. This allows multiple try tasks to route to shared error-handling tasks without duplicating inline do blocks. Signed-off-by: Ricardo Zanini --- dsl-reference.md | 1 + examples/try-catch-then-directive.yaml | 25 +++++++++++++++++++++++++ schema/workflow.yaml | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 examples/try-catch-then-directive.yaml diff --git a/dsl-reference.md b/dsl-reference.md index 23156db3..6a97b2fb 100644 --- a/dsl-reference.md +++ b/dsl-reference.md @@ -1255,6 +1255,7 @@ Defines the configuration of a catch clause, which a concept used to catch error | exceptWhen | `string` | `no` | A runtime expression used to determine whether or not to catch the filtered error. | | retry | `string`
[`retryPolicy`](#retry) | `no` | The [`retry policy`](#retry) to use, if any, when catching [`errors`](#error).
*If a `string`, must be the name of a [retry policy](#retry) defined in the [workflow's reusable components](#use).* | | do | [`map[string, task]`](#task) | `no` | The definition of the task(s) to run when catching an error. | +| then | [`flowDirective`](#flow-directive) | `no` | The [flow directive](#flow-directive) to execute after catching the error. | #### Wait diff --git a/examples/try-catch-then-directive.yaml b/examples/try-catch-then-directive.yaml new file mode 100644 index 00000000..9d919406 --- /dev/null +++ b/examples/try-catch-then-directive.yaml @@ -0,0 +1,25 @@ +document: + dsl: '1.0.3' + namespace: test + name: try-catch-then-directive + version: '0.1.0' +do: + - trySomething: + try: + - callExternalService: + call: http + with: + method: get + endpoint: https://external-service.example.com/api + catch: + errors: + with: + type: https://serverlessworkflow.io/dsl/errors/types/communication + status: 503 + then: handleError + - continueProcessing: + set: + status: ok + - handleError: + set: + status: failed diff --git a/schema/workflow.yaml b/schema/workflow.yaml index a443ed50..d58cff35 100644 --- a/schema/workflow.yaml +++ b/schema/workflow.yaml @@ -1054,6 +1054,10 @@ $defs: $ref: '#/$defs/taskList' title: TryTaskCatchDo description: The definition of the task(s) to run when catching an error. + then: + $ref: '#/$defs/flowDirective' + title: TryTaskCatchThen + description: The flow directive to execute after catching the error. waitTask: type: object title: WaitTask From a25a5a28f98057d10d78073b32e2b42d423a0c6d Mon Sep 17 00:00:00 2001 From: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Date: Thu, 23 Jul 2026 15:31:51 -0400 Subject: [PATCH 2/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- examples/try-catch-then-directive.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/try-catch-then-directive.yaml b/examples/try-catch-then-directive.yaml index 9d919406..5afb5cfa 100644 --- a/examples/try-catch-then-directive.yaml +++ b/examples/try-catch-then-directive.yaml @@ -20,6 +20,7 @@ do: - continueProcessing: set: status: ok + then: end - handleError: set: status: failed From 1873ed0b9bd6f01956453cfcd4345d95f24d4da0 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Date: Thu, 23 Jul 2026 15:45:37 -0400 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- dsl-reference.md | 2 +- schema/workflow.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dsl-reference.md b/dsl-reference.md index f7e91cd6..9df97ed5 100644 --- a/dsl-reference.md +++ b/dsl-reference.md @@ -1255,7 +1255,7 @@ Defines the configuration of a catch clause, which a concept used to catch error | exceptWhen | `string` | `no` | A runtime expression used to determine whether or not to catch the filtered error. | | retry | `string`
[`retryPolicy`](#retry) | `no` | The [`retry policy`](#retry) to use, if any, when catching [`errors`](#error).
*If a `string`, must be the name of a [retry policy](#retry) defined in the [workflow's reusable components](#use).* | | do | [`map[string, task]`](#task) | `no` | The definition of the task(s) to run when catching an error. | -| then | [`flowDirective`](#flow-directive) | `no` | The [flow directive](#flow-directive) to execute after catching the error. | +| then | [`flowDirective`](#flow-directive) | `no` | The [flow directive](#flow-directive) to execute for the error path after the error has been caught (and after executing any `do` tasks, if set). This determines the next transition for the catch path (overriding the try task’s normal completion flow). | #### Wait diff --git a/schema/workflow.yaml b/schema/workflow.yaml index d58cff35..8a54681c 100644 --- a/schema/workflow.yaml +++ b/schema/workflow.yaml @@ -1057,7 +1057,7 @@ $defs: then: $ref: '#/$defs/flowDirective' title: TryTaskCatchThen - description: The flow directive to execute after catching the error. + description: The flow directive to execute for the error path after the error has been caught (and after executing any `do` tasks, if set). When set, this determines the next transition instead of the try task's top-level `then` or the default sequential flow. waitTask: type: object title: WaitTask From 045037c6e32fdaaa00904c57eed84555f4bc3b11 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Thu, 23 Jul 2026 15:52:43 -0400 Subject: [PATCH 4/4] Rename handleError to recordFailure in catch-then example Address review feedback: the `do` block handles the error, this task just records the outcome after catch processing. Signed-off-by: Ricardo Zanini --- examples/try-catch-then-directive.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/try-catch-then-directive.yaml b/examples/try-catch-then-directive.yaml index 5afb5cfa..e7972bc7 100644 --- a/examples/try-catch-then-directive.yaml +++ b/examples/try-catch-then-directive.yaml @@ -16,11 +16,11 @@ do: with: type: https://serverlessworkflow.io/dsl/errors/types/communication status: 503 - then: handleError + then: recordFailure - continueProcessing: set: status: ok then: end - - handleError: + - recordFailure: set: status: failed