You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dsl-reference.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -285,6 +285,7 @@ The Serverless Workflow DSL defines a list of [tasks](#task) that **must be** su
285
285
| export | [`export`](#export) | `no` | An object used to customize the content of the workflow context. |
286
286
| timeout | `string`<br>[`timeout`](#timeout) | `no` | The configuration of the task's timeout, if any.<br>*If a `string`, must be the name of a [timeout](#timeout) defined in the [workflow's reusable components](#use).* |
287
287
| then | [`flowDirective`](#flow-directive) | `no` | The flow directive to execute next.<br>*If not set, defaults to `continue`.* |
288
+
| catch | [`catch`](#catch) | `no` | Used to handle errors and define retry policies for the current task. See [Catch](#catch) for detailed documentation. |
288
289
| metadata | `map` | `no` | Additional information about the task. |
289
290
290
291
#### Call
@@ -1111,7 +1112,12 @@ do:
1111
1112
1112
1113
##### Catch
1113
1114
1114
-
Defines the configuration of a catch clause, which a concept used to catch errors.
1115
+
Defines the configuration of a catch clause, which is a concept used to catch errors and to define what should happen when they occur.
1116
+
Catch nodes can be used in two ways:
1117
+
1. With any [`task`](#task) to handle errors on that single task
1118
+
2. With the [`try`](#try) task to handle errors on a group of tasks
1119
+
1120
+
This flexibility allows for both fine-grained error handling at the task level and broader error handling for groups of tasks.
1115
1121
1116
1122
###### Properties
1117
1123
@@ -1124,6 +1130,36 @@ Defines the configuration of a catch clause, which a concept used to catch error
1124
1130
| retry | `string`<br>[`retryPolicy`](#retry) | `no` | The [`retry policy`](#retry) to use, if any, when catching [`errors`](#error).<br>*If a `string`, must be the name of a [retry policy](#retry) defined in the [workflow's reusable components](#use).* |
1125
1131
| do | [`map[string, task]`](#task) | `no` | The definition of the task(s) to run when catching an error. |
Copy file name to clipboardExpand all lines: dsl.md
+97-1Lines changed: 97 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -483,7 +483,7 @@ See the [DSL reference](dsl-reference.md#error) for more details about errors.
483
483
484
484
#### Retries
485
485
486
-
Errors are critical for both authors and runtimes as they provide a means to communicate and describe the occurrence of problems. This, in turn, enables the definition of mechanisms to catch and act upon these errors. For instance, some errors caught using a [`try`](dsl-reference.md#try) block may be transient and temporary, such as a `503 Service Unavailable`. In such cases, the DSL provides a mechanism to retry a faulted task, allowing for recovery from temporary issues.
486
+
Errors are critical for both authors and runtimes as they provide a means to communicate and describe the occurrence of problems. This, in turn, enables the definition of mechanisms to catch and act upon these errors. For instance, some errors may be transient and temporary, such as a `503 Service Unavailable`. In such cases, the DSL provides a mechanism to retry a [`faulted task`](dsl-reference.md#task), or a [`group of tasks`](dsl-reference.md#try), allowing for recovery from temporary issues.
487
487
488
488
*Retrying 5 times when an error with 503 is caught:*
489
489
```yaml
@@ -507,6 +507,102 @@ catch:
507
507
count: 5
508
508
```
509
509
510
+
#### Task-Level Error Handling
511
+
512
+
In addition to the try-catch mechanism, any task can define its own error handling using the `catch` property. This allows for more granular error handling at the task level without the need to wrap the task in a try block.
513
+
514
+
Task-level error handling provides several benefits:
515
+
1. More concise and readable code by avoiding nested try blocks
516
+
2. Direct association of error handling with the task that might fail
517
+
3. Reusability of error handling logic when the task is used as a function
518
+
519
+
*Example of task-level error handling:*
520
+
```yaml
521
+
do:
522
+
- getPetById:
523
+
call: http
524
+
with:
525
+
method: get
526
+
endpoint:
527
+
uri: https://petstore.swagger.io/v2/pet/{id}
528
+
catch:
529
+
errors:
530
+
with:
531
+
status: 404
532
+
do:
533
+
- createDefaultPet:
534
+
call: http
535
+
with:
536
+
method: post
537
+
endpoint:
538
+
uri: https://petstore.swagger.io/v2/pet
539
+
body:
540
+
id: ${ .id }
541
+
name: "Default Pet"
542
+
status: "available"
543
+
```
544
+
545
+
*Example comparing try-catch with task-level catch:*
546
+
```yaml
547
+
# Using try-catch
548
+
do:
549
+
- handlePet:
550
+
try:
551
+
call: http
552
+
with:
553
+
method: get
554
+
endpoint:
555
+
uri: https://petstore.swagger.io/v2/pet/{id}
556
+
catch:
557
+
errors:
558
+
with:
559
+
status: 404
560
+
do:
561
+
- createDefaultPet:
562
+
call: http
563
+
with:
564
+
method: post
565
+
endpoint:
566
+
uri: https://petstore.swagger.io/v2/pet
567
+
body:
568
+
id: ${ .id }
569
+
name: "Default Pet"
570
+
status: "available"
571
+
572
+
# Using task-level catch (more concise)
573
+
do:
574
+
- getPetById:
575
+
call: http
576
+
with:
577
+
method: get
578
+
endpoint:
579
+
uri: https://petstore.swagger.io/v2/pet/{id}
580
+
catch:
581
+
errors:
582
+
with:
583
+
status: 404
584
+
do:
585
+
- createDefaultPet:
586
+
call: http
587
+
with:
588
+
method: post
589
+
endpoint:
590
+
uri: https://petstore.swagger.io/v2/pet
591
+
body:
592
+
id: ${ .id }
593
+
name: "Default Pet"
594
+
status: "available"
595
+
```
596
+
597
+
Task-level error handling supports all the same features as try-catch:
598
+
- Error filtering with `with`
599
+
- Error variable naming with `as`
600
+
- Conditional catching with `when` and `exceptWhen`
601
+
- Retry policies
602
+
- Task list execution with `do`
603
+
604
+
See the [DSL reference](dsl-reference.md#task-catch) for more details about task-level error handling.
605
+
510
606
### Timeouts
511
607
512
608
Workflows and tasks alike can be configured to timeout after a defined amount of time.
0 commit comments