From 9a868dedea769962264642afde33065ed713f2f5 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Mon, 28 Oct 2024 15:38:39 +0000 Subject: [PATCH 01/13] Reenforce that for NonRetryableErrors, users need to manage the error or the Workflow will fail --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index cdfaf298f75499..7dfecfa39abac3 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -87,7 +87,7 @@ let someState = step.do("call an API", { }, async () => { /* Step code goes here /* } ``` -## Force a Workflow to fail +## Force a Workflow Instance to fail You can also force a Workflow instance to fail and _not_ retry by throwing a `NonRetryableError` from within the step. @@ -111,3 +111,5 @@ export class MyWorkflow extends WorkflowEntrypoint { ``` The Workflow instance itself will fail immediately, no further steps will be invoked, and the Workflow will not be retried. + +Users can catch this error if they intend to continue the Workflow execution. Otherwise, the Workflow will fail. From d5b637101087cd0ba5fd6cce277e8475632f2332 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Mon, 28 Oct 2024 16:11:37 +0000 Subject: [PATCH 02/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index 7dfecfa39abac3..37e48ef5b68ea6 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -87,7 +87,7 @@ let someState = step.do("call an API", { }, async () => { /* Step code goes here /* } ``` -## Force a Workflow Instance to fail +## Force a Workflow instance to fail You can also force a Workflow instance to fail and _not_ retry by throwing a `NonRetryableError` from within the step. From 028a9be65323be178705268f5ad015f14efcad90 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Mon, 28 Oct 2024 16:11:37 +0000 Subject: [PATCH 03/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index 37e48ef5b68ea6..dafe4b651222c3 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -112,4 +112,4 @@ export class MyWorkflow extends WorkflowEntrypoint { The Workflow instance itself will fail immediately, no further steps will be invoked, and the Workflow will not be retried. -Users can catch this error if they intend to continue the Workflow execution. Otherwise, the Workflow will fail. +Like other Errors, any uncaught exceptions that propagate to the top level will cause the Workflow to end execution in an Errored state. Catch the `NonRetryableError` to continue Workflow execution. From bdc1cba93b6b0a504a5816d2fcd2cbdaa9eaf4e0 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Mon, 28 Oct 2024 19:41:38 +0000 Subject: [PATCH 04/13] added code example to catch NonRetryableError --- .../workflows/build/sleeping-and-retrying.mdx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index dafe4b651222c3..d3968112a03f5c 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -112,4 +112,22 @@ export class MyWorkflow extends WorkflowEntrypoint { The Workflow instance itself will fail immediately, no further steps will be invoked, and the Workflow will not be retried. -Like other Errors, any uncaught exceptions that propagate to the top level will cause the Workflow to end execution in an Errored state. Catch the `NonRetryableError` to continue Workflow execution. +Like other Errors, any uncaught exceptions that propagate to the top level will cause the Workflow to end execution in an Errored state. Catch the `NonRetryableError` to continue Workflow execution: + +```ts +... +try { + await step.do('task', async () => { + // work not to be retried + throw new NonRetryableError('oh no'); + }); +} catch { + console.log('error was thrown'); +} + +// the Workflow will not fail and can continue its execution + +await step.do(next task, async() => { + // more work to be done +}); +``` From c23540123fa4ce062655c7be676456893ea1e88c Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Mon, 28 Oct 2024 19:43:05 +0000 Subject: [PATCH 05/13] imnor improvement --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index d3968112a03f5c..5566786d8886e8 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -125,9 +125,10 @@ try { console.log('error was thrown'); } -// the Workflow will not fail and can continue its execution +// the Workflow will not fail and will continue its execution -await step.do(next task, async() => { +await step.do('next-task', async() => { // more work to be done }); +... ``` From 52790bd4c8386abd8125cfa3edb7203dc31073d8 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Tue, 29 Oct 2024 18:29:32 +0000 Subject: [PATCH 06/13] better example of how to manage catch of steps and example --- .../workflows/build/sleeping-and-retrying.mdx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index 5566786d8886e8..db9344e8bf9026 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -112,12 +112,22 @@ export class MyWorkflow extends WorkflowEntrypoint { The Workflow instance itself will fail immediately, no further steps will be invoked, and the Workflow will not be retried. -Like other Errors, any uncaught exceptions that propagate to the top level will cause the Workflow to end execution in an Errored state. Catch the `NonRetryableError` to continue Workflow execution: +## Avoid a Workflow instance to fail + +Any uncaught exceptions that propagate to the top level, or any steps that reach their retry limit, will cause the Workflow to end execution in an Errored state. However, this may not be intended, as for example, a cleanup of previous step executions may be required. + +To allow the Workflow to continue its execution, surround the intended steps that are allowed to fail with a try/catch. + +Simple example of a Worflow with a cleanup step: ```ts ... +await step.do('task', async () => { + // work to be done +}); + try { - await step.do('task', async () => { + await step.do('non-retryable-task', async () => { // work not to be retried throw new NonRetryableError('oh no'); }); @@ -127,8 +137,8 @@ try { // the Workflow will not fail and will continue its execution -await step.do('next-task', async() => { - // more work to be done +await step.do('cleanup-task', async() => { + // cleanup work, revert execution from 'task' step }); ... ``` From 16670e93c981e450b6095e935505a2b21a6b5b7d Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 8 Nov 2024 10:17:52 +0000 Subject: [PATCH 07/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index db9344e8bf9026..dd9643451d39a9 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -112,7 +112,7 @@ export class MyWorkflow extends WorkflowEntrypoint { The Workflow instance itself will fail immediately, no further steps will be invoked, and the Workflow will not be retried. -## Avoid a Workflow instance to fail +## Catch Workflow errors Any uncaught exceptions that propagate to the top level, or any steps that reach their retry limit, will cause the Workflow to end execution in an Errored state. However, this may not be intended, as for example, a cleanup of previous step executions may be required. From 25365a9173f416bed7d33d18170ea9a085b49348 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 8 Nov 2024 10:18:10 +0000 Subject: [PATCH 08/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index dd9643451d39a9..87edace5c2a841 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -114,7 +114,9 @@ The Workflow instance itself will fail immediately, no further steps will be inv ## Catch Workflow errors -Any uncaught exceptions that propagate to the top level, or any steps that reach their retry limit, will cause the Workflow to end execution in an Errored state. However, this may not be intended, as for example, a cleanup of previous step executions may be required. +Any uncaught exceptions that propagate to the top level, or any steps that reach their retry limit, will cause the Workflow to end execution in an `Errored` state. + +If you want to avoid this, you can catch exceptions emitted by a `step`. This can be useful if you need to trigger clean-up tasks or have conditional logic that triggers additional steps. To allow the Workflow to continue its execution, surround the intended steps that are allowed to fail with a try/catch. From 1fca47b0908950ccaf1076ae1cf04db8e9195a2f Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 8 Nov 2024 10:18:25 +0000 Subject: [PATCH 09/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index 87edace5c2a841..b8a40cc4d5182d 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -118,7 +118,7 @@ Any uncaught exceptions that propagate to the top level, or any steps that reach If you want to avoid this, you can catch exceptions emitted by a `step`. This can be useful if you need to trigger clean-up tasks or have conditional logic that triggers additional steps. -To allow the Workflow to continue its execution, surround the intended steps that are allowed to fail with a try/catch. +To allow the Workflow to continue its execution, surround the intended steps that are allowed to fail with a `try-catch` block. Simple example of a Worflow with a cleanup step: From 21f878ce129fd1ab9911c3c855662f1676ab7272 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 8 Nov 2024 10:18:50 +0000 Subject: [PATCH 10/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index b8a40cc4d5182d..08097c46403906 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -120,7 +120,6 @@ If you want to avoid this, you can catch exceptions emitted by a `step`. This ca To allow the Workflow to continue its execution, surround the intended steps that are allowed to fail with a `try-catch` block. -Simple example of a Worflow with a cleanup step: ```ts ... From 744bbd7613c83d7ed8b108305b3de4c42b7c10e2 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 8 Nov 2024 10:18:58 +0000 Subject: [PATCH 11/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index 08097c46403906..f6d7ce996a0da8 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -132,7 +132,7 @@ try { // work not to be retried throw new NonRetryableError('oh no'); }); -} catch { +} catch(e as Error) { console.log('error was thrown'); } From 11582c3e749f2acf5ec9c83c6a6641745e863466 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 8 Nov 2024 10:19:56 +0000 Subject: [PATCH 12/13] Update src/content/docs/workflows/build/sleeping-and-retrying.mdx Co-authored-by: Matt Silverlock --- src/content/docs/workflows/build/sleeping-and-retrying.mdx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index f6d7ce996a0da8..07341949ac61bf 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -133,7 +133,10 @@ try { throw new NonRetryableError('oh no'); }); } catch(e as Error) { - console.log('error was thrown'); + console.log(`Step failed: ${e.message}`); + await step.do('clean up', async () => { + // Clean up code here + } } // the Workflow will not fail and will continue its execution From 6bed40fd8a8747ceb7ebe63754b322e38d1b8c07 Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Fri, 8 Nov 2024 12:59:38 +0000 Subject: [PATCH 13/13] minor example cleanup --- .../docs/workflows/build/sleeping-and-retrying.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/content/docs/workflows/build/sleeping-and-retrying.mdx b/src/content/docs/workflows/build/sleeping-and-retrying.mdx index 07341949ac61bf..74143cf8d5ec83 100644 --- a/src/content/docs/workflows/build/sleeping-and-retrying.mdx +++ b/src/content/docs/workflows/build/sleeping-and-retrying.mdx @@ -134,15 +134,15 @@ try { }); } catch(e as Error) { console.log(`Step failed: ${e.message}`); - await step.do('clean up', async () => { + await step.do('clean-up-task', async () => { // Clean up code here - } + }); } // the Workflow will not fail and will continue its execution -await step.do('cleanup-task', async() => { - // cleanup work, revert execution from 'task' step +await step.do('next-task', async() => { + // more work to be done }); ... ```