Skip to content

Commit 57d467c

Browse files
committed
NonRetryableError
1 parent 883e24a commit 57d467c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/content/docs/workflows/build/sleeping-and-retrying.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,27 @@ let someState = step.do("call an API", {
8484
timeout: "30 minutes",
8585
}, async () => { /* Step code goes here /* }
8686
```
87+
88+
### Force a step to fail
89+
90+
You can also force a Workflow instance to fail and _not_ retry by throwing a `NonRetryableError` from within the step.
91+
92+
This can be useful when you detect a terminal (permanent) error from an upstream system (such as an authentication failure) or other errors where retrying would not help.
93+
94+
```ts
95+
// Import the NonRetryableError definition
96+
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent, NonRetryableError } from 'cloudflare:workers';
97+
98+
// In your step code:
99+
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
100+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
101+
await step.do("some step", async () => {
102+
if !(event.data) {
103+
throw NonRetryableError("event.data did not contain the expected payload")
104+
}
105+
})
106+
}
107+
}
108+
```
109+
110+
The Workflow instance itself will fail immediately, no further steps will be invoked, and the Workflow will not be retried.

0 commit comments

Comments
 (0)