Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/content/docs/workflows/build/sleeping-and-retrying.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -111,3 +111,34 @@ export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
```

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

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('non-retryable-task', async () => {
// work not to be retried
throw new NonRetryableError('oh no');
});
} catch {
console.log('error was thrown');
}

// the Workflow will not fail and will continue its execution

await step.do('cleanup-task', async() => {
// cleanup work, revert execution from 'task' step
});
...
```
Loading