workflow 4.2.0-beta.70 → 4.2.0-beta.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +1 -1
- package/dist/internal/builtins.d.ts +3 -3
- package/dist/internal/builtins.d.ts.map +1 -1
- package/dist/internal/builtins.js +7 -7
- package/dist/internal/errors.d.ts +1 -1
- package/dist/internal/errors.d.ts.map +1 -1
- package/dist/internal/errors.js +2 -2
- package/dist/observability.d.ts +20 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +20 -0
- package/docs/ai/chat-session-modeling.mdx +4 -4
- package/docs/ai/defining-tools.mdx +7 -1
- package/docs/ai/index.mdx +8 -5
- package/docs/ai/message-queueing.mdx +8 -6
- package/docs/ai/resumable-streams.mdx +37 -4
- package/docs/ai/sleep-and-delays.mdx +2 -0
- package/docs/api-reference/index.mdx +3 -0
- package/docs/api-reference/meta.json +1 -1
- package/docs/api-reference/workflow/define-hook.mdx +2 -0
- package/docs/api-reference/workflow/get-writable.mdx +1 -0
- package/docs/api-reference/workflow-ai/durable-agent.mdx +7 -5
- package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +2 -0
- package/docs/api-reference/workflow-api/get-run.mdx +14 -0
- package/docs/api-reference/workflow-api/get-world.mdx +105 -0
- package/docs/api-reference/workflow-api/start.mdx +24 -0
- package/docs/api-reference/workflow-errors/entity-conflict-error.mdx +60 -0
- package/docs/api-reference/workflow-errors/hook-not-found-error.mdx +90 -0
- package/docs/api-reference/workflow-errors/meta.json +16 -0
- package/docs/api-reference/workflow-errors/run-expired-error.mdx +58 -0
- package/docs/api-reference/workflow-errors/step-not-registered-error.mdx +56 -0
- package/docs/api-reference/workflow-errors/throttle-error.mdx +62 -0
- package/docs/api-reference/workflow-errors/too-early-error.mdx +62 -0
- package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +57 -0
- package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +56 -0
- package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +62 -0
- package/docs/api-reference/workflow-errors/workflow-run-not-found-error.mdx +56 -0
- package/docs/api-reference/workflow-errors/workflow-world-error.mdx +79 -0
- package/docs/api-reference/workflow-serde/index.mdx +52 -0
- package/docs/api-reference/workflow-serde/meta.json +3 -0
- package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +70 -0
- package/docs/api-reference/workflow-serde/workflow-serialize.mdx +75 -0
- package/docs/changelog/index.mdx +15 -0
- package/docs/changelog/meta.json +5 -0
- package/docs/deploying/building-a-world.mdx +20 -0
- package/docs/deploying/world/vercel-world.mdx +2 -1
- package/docs/errors/hook-conflict.mdx +9 -3
- package/docs/errors/index.mdx +6 -0
- package/docs/errors/step-not-registered.mdx +66 -0
- package/docs/errors/webhook-invalid-respond-with-value.mdx +10 -0
- package/docs/errors/webhook-response-not-sent.mdx +8 -0
- package/docs/errors/workflow-not-registered.mdx +64 -0
- package/docs/foundations/common-patterns.mdx +4 -0
- package/docs/foundations/errors-and-retries.mdx +29 -0
- package/docs/foundations/serialization.mdx +211 -0
- package/docs/foundations/streaming.mdx +22 -0
- package/docs/getting-started/index.mdx +3 -3
- package/docs/getting-started/meta.json +15 -0
- package/docs/getting-started/nestjs.mdx +4 -8
- package/docs/how-it-works/encryption.mdx +93 -0
- package/docs/how-it-works/meta.json +2 -1
- package/docs/observability/index.mdx +3 -0
- package/package.json +18 -12
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: EntityConflictError
|
|
3
|
+
description: Thrown when a storage operation conflicts with the current entity state.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch EntityConflictError when a world operation conflicts with entity state (e.g. duplicate events or runs).
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-errors/workflow-world-error
|
|
8
|
+
- /docs/api-reference/workflow-errors/run-expired-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`EntityConflictError` is thrown by world implementations when a storage operation conflicts with the current entity state. This includes cases like creating a run that already exists or writing an event that has already been persisted.
|
|
12
|
+
|
|
13
|
+
It corresponds to HTTP 409 Conflict semantics.
|
|
14
|
+
|
|
15
|
+
<Callout>
|
|
16
|
+
The Workflow runtime handles this error automatically during replay and event deduplication. You will only encounter it when interacting with world storage APIs directly.
|
|
17
|
+
</Callout>
|
|
18
|
+
|
|
19
|
+
```typescript lineNumbers
|
|
20
|
+
import { EntityConflictError } from "workflow/errors"
|
|
21
|
+
declare const world: { events: { create(...args: any[]): Promise<any> } }; // @setup
|
|
22
|
+
declare const runId: string; // @setup
|
|
23
|
+
declare const event: any; // @setup
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await world.events.create(runId, event);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (EntityConflictError.is(error)) { // [!code highlight]
|
|
29
|
+
// Event already exists — safe to ignore during replay
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API Signature
|
|
35
|
+
|
|
36
|
+
### Properties
|
|
37
|
+
|
|
38
|
+
<TSDoc
|
|
39
|
+
definition={`
|
|
40
|
+
interface EntityConflictError {
|
|
41
|
+
/** The error message. */
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export default EntityConflictError;`}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
### Static Methods
|
|
48
|
+
|
|
49
|
+
#### `EntityConflictError.is(value)`
|
|
50
|
+
|
|
51
|
+
Type-safe check for `EntityConflictError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { EntityConflictError } from "workflow/errors"
|
|
55
|
+
declare const error: unknown; // @setup
|
|
56
|
+
|
|
57
|
+
if (EntityConflictError.is(error)) {
|
|
58
|
+
// error is typed as EntityConflictError
|
|
59
|
+
}
|
|
60
|
+
```
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: HookNotFoundError
|
|
3
|
+
description: Thrown when resuming a hook that does not exist.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch HookNotFoundError when calling resumeHook() or resumeWebhook() with a token that doesn't match any active hook.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow/create-hook
|
|
8
|
+
- /docs/api-reference/workflow/define-hook
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`HookNotFoundError` is thrown when calling `resumeHook()` or `resumeWebhook()` with a token that does not match any active hook. This typically happens when:
|
|
12
|
+
|
|
13
|
+
- The hook has expired (past its TTL)
|
|
14
|
+
- The hook was already consumed and disposed
|
|
15
|
+
- The workflow has not started yet, so the hook does not exist
|
|
16
|
+
|
|
17
|
+
```typescript lineNumbers
|
|
18
|
+
import { HookNotFoundError } from "workflow/errors"
|
|
19
|
+
declare function resumeHook(token: string, payload: any): Promise<any>; // @setup
|
|
20
|
+
declare const token: string; // @setup
|
|
21
|
+
declare const payload: any; // @setup
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await resumeHook(token, payload);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (HookNotFoundError.is(error)) { // [!code highlight]
|
|
27
|
+
console.error("Hook not found:", error.token);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API Signature
|
|
33
|
+
|
|
34
|
+
### Properties
|
|
35
|
+
|
|
36
|
+
<TSDoc
|
|
37
|
+
definition={`
|
|
38
|
+
interface HookNotFoundError {
|
|
39
|
+
/** The hook token that was not found. */
|
|
40
|
+
token: string;
|
|
41
|
+
/** The error message. */
|
|
42
|
+
message: string;
|
|
43
|
+
}
|
|
44
|
+
export default HookNotFoundError;`}
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
### Static Methods
|
|
48
|
+
|
|
49
|
+
#### `HookNotFoundError.is(value)`
|
|
50
|
+
|
|
51
|
+
Type-safe check for `HookNotFoundError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { HookNotFoundError } from "workflow/errors"
|
|
55
|
+
declare const error: unknown; // @setup
|
|
56
|
+
|
|
57
|
+
if (HookNotFoundError.is(error)) {
|
|
58
|
+
// error is typed as HookNotFoundError
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Examples
|
|
63
|
+
|
|
64
|
+
### Resume hook or start workflow
|
|
65
|
+
|
|
66
|
+
A common pattern for idempotent workflows is to try resuming a hook, and if it doesn't exist yet, start a new workflow run with the input data.
|
|
67
|
+
|
|
68
|
+
<Callout>
|
|
69
|
+
This "resume or start" pattern is not atomic — there is a small window where a race condition is possible. A better native approach is being worked on, but this pattern works well for many use cases.
|
|
70
|
+
</Callout>
|
|
71
|
+
|
|
72
|
+
```typescript lineNumbers
|
|
73
|
+
import { HookNotFoundError } from "workflow/errors"
|
|
74
|
+
declare function resumeHook(token: string, data: unknown): Promise<any>; // @setup
|
|
75
|
+
declare function startWorkflow(name: string, data: unknown): Promise<any>; // @setup
|
|
76
|
+
|
|
77
|
+
async function handleIncomingEvent(token: string, data: unknown) {
|
|
78
|
+
try {
|
|
79
|
+
// Try to resume an existing hook
|
|
80
|
+
await resumeHook(token, data);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (HookNotFoundError.is(error)) { // [!code highlight]
|
|
83
|
+
// Hook doesn't exist yet — start a new workflow run
|
|
84
|
+
await startWorkflow("processEvent", data); // [!code highlight]
|
|
85
|
+
} else {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "workflow/errors",
|
|
3
|
+
"pages": [
|
|
4
|
+
"hook-not-found-error",
|
|
5
|
+
"step-not-registered-error",
|
|
6
|
+
"workflow-not-registered-error",
|
|
7
|
+
"workflow-run-not-found-error",
|
|
8
|
+
"workflow-run-failed-error",
|
|
9
|
+
"workflow-run-cancelled-error",
|
|
10
|
+
"workflow-world-error",
|
|
11
|
+
"throttle-error",
|
|
12
|
+
"entity-conflict-error",
|
|
13
|
+
"run-expired-error",
|
|
14
|
+
"too-early-error"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: RunExpiredError
|
|
3
|
+
description: Thrown when a workflow run has expired and can no longer be operated on.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch RunExpiredError when a workflow run has expired and can no longer accept operations.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-errors/workflow-world-error
|
|
8
|
+
- /docs/api-reference/workflow-errors/entity-conflict-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`RunExpiredError` is thrown by world implementations when a workflow run has expired and can no longer be operated on. It corresponds to HTTP 410 Gone semantics.
|
|
12
|
+
|
|
13
|
+
<Callout>
|
|
14
|
+
The Workflow runtime handles this error automatically. You will only encounter it when interacting with world storage APIs directly.
|
|
15
|
+
</Callout>
|
|
16
|
+
|
|
17
|
+
```typescript lineNumbers
|
|
18
|
+
import { RunExpiredError } from "workflow/errors"
|
|
19
|
+
declare const world: { events: { create(...args: any[]): Promise<any> } }; // @setup
|
|
20
|
+
declare const runId: string; // @setup
|
|
21
|
+
declare const event: any; // @setup
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
await world.events.create(runId, event);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (RunExpiredError.is(error)) { // [!code highlight]
|
|
27
|
+
console.log("Run has expired and can no longer accept events");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API Signature
|
|
33
|
+
|
|
34
|
+
### Properties
|
|
35
|
+
|
|
36
|
+
<TSDoc
|
|
37
|
+
definition={`
|
|
38
|
+
interface RunExpiredError {
|
|
39
|
+
/** The error message. */
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
export default RunExpiredError;`}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
### Static Methods
|
|
46
|
+
|
|
47
|
+
#### `RunExpiredError.is(value)`
|
|
48
|
+
|
|
49
|
+
Type-safe check for `RunExpiredError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { RunExpiredError } from "workflow/errors"
|
|
53
|
+
declare const error: unknown; // @setup
|
|
54
|
+
|
|
55
|
+
if (RunExpiredError.is(error)) {
|
|
56
|
+
// error is typed as RunExpiredError
|
|
57
|
+
}
|
|
58
|
+
```
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: StepNotRegisteredError
|
|
3
|
+
description: Thrown when a step function is not registered in the current deployment.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch StepNotRegisteredError when a step function cannot be found during execution.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/errors/step-not-registered
|
|
8
|
+
- /docs/api-reference/workflow-errors/workflow-not-registered-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`StepNotRegisteredError` is thrown when the runtime tries to execute a step function that is not registered in the current deployment. This is an infrastructure error — not a user code error. It typically indicates a build or bundling issue that caused the step to not be included in the deployment.
|
|
12
|
+
|
|
13
|
+
When this error occurs, the step fails (like a `FatalError`) and control is passed back to the workflow function, which can handle the failure gracefully.
|
|
14
|
+
|
|
15
|
+
```typescript lineNumbers
|
|
16
|
+
import { StepNotRegisteredError } from "workflow/errors"
|
|
17
|
+
declare const error: unknown; // @setup
|
|
18
|
+
|
|
19
|
+
if (StepNotRegisteredError.is(error)) { // [!code highlight]
|
|
20
|
+
console.error("Step not registered:", error.stepName);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API Signature
|
|
25
|
+
|
|
26
|
+
### Properties
|
|
27
|
+
|
|
28
|
+
<TSDoc
|
|
29
|
+
definition={`
|
|
30
|
+
interface StepNotRegisteredError {
|
|
31
|
+
/** The name of the step function that was not found. */
|
|
32
|
+
stepName: string;
|
|
33
|
+
/** The error message. */
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
export default StepNotRegisteredError;`}
|
|
37
|
+
/>
|
|
38
|
+
|
|
39
|
+
### Static Methods
|
|
40
|
+
|
|
41
|
+
#### `StepNotRegisteredError.is(value)`
|
|
42
|
+
|
|
43
|
+
Type-safe check for `StepNotRegisteredError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
44
|
+
|
|
45
|
+
<Callout>
|
|
46
|
+
The `.is()` method works in server-side Node.js code (API routes, middleware, hooks). Inside `"use workflow"` functions, step errors arrive deserialized from the event log and won't be actual `StepNotRegisteredError` instances — use `error.message` matching instead. See the [troubleshooting page](/docs/errors/step-not-registered) for workflow-side error handling examples.
|
|
47
|
+
</Callout>
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { StepNotRegisteredError } from "workflow/errors"
|
|
51
|
+
declare const error: unknown; // @setup
|
|
52
|
+
|
|
53
|
+
if (StepNotRegisteredError.is(error)) {
|
|
54
|
+
// error is typed as StepNotRegisteredError
|
|
55
|
+
}
|
|
56
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ThrottleError
|
|
3
|
+
description: Thrown when a request is rate-limited by the workflow backend.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch ThrottleError when a workflow storage operation is rate-limited (HTTP 429).
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-errors/workflow-world-error
|
|
8
|
+
- /docs/api-reference/workflow-errors/too-early-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`ThrottleError` is thrown when a request to the workflow backend is rate-limited. It corresponds to HTTP 429 Too Many Requests semantics.
|
|
12
|
+
|
|
13
|
+
The `retryAfter` property contains the number of seconds to wait before retrying.
|
|
14
|
+
|
|
15
|
+
<Callout>
|
|
16
|
+
The Workflow runtime handles this error automatically by backing off and retrying. You will only encounter it when interacting with world storage APIs directly.
|
|
17
|
+
</Callout>
|
|
18
|
+
|
|
19
|
+
```typescript lineNumbers
|
|
20
|
+
import { ThrottleError } from "workflow/errors"
|
|
21
|
+
declare const world: { events: { create(...args: any[]): Promise<any> } }; // @setup
|
|
22
|
+
declare const runId: string; // @setup
|
|
23
|
+
declare const event: any; // @setup
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await world.events.create(runId, event);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (ThrottleError.is(error)) { // [!code highlight]
|
|
29
|
+
console.log(`Rate limited. Retry after ${error.retryAfter} seconds`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API Signature
|
|
35
|
+
|
|
36
|
+
### Properties
|
|
37
|
+
|
|
38
|
+
<TSDoc
|
|
39
|
+
definition={`
|
|
40
|
+
interface ThrottleError {
|
|
41
|
+
/** The number of seconds to wait before retrying. Present when the server sends a Retry-After header. */
|
|
42
|
+
retryAfter?: number;
|
|
43
|
+
/** The error message. */
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
export default ThrottleError;`}
|
|
47
|
+
/>
|
|
48
|
+
|
|
49
|
+
### Static Methods
|
|
50
|
+
|
|
51
|
+
#### `ThrottleError.is(value)`
|
|
52
|
+
|
|
53
|
+
Type-safe check for `ThrottleError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { ThrottleError } from "workflow/errors"
|
|
57
|
+
declare const error: unknown; // @setup
|
|
58
|
+
|
|
59
|
+
if (ThrottleError.is(error)) {
|
|
60
|
+
// error is typed as ThrottleError
|
|
61
|
+
}
|
|
62
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TooEarlyError
|
|
3
|
+
description: Thrown when a request is made before the system is ready to process it.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch TooEarlyError when a world operation is attempted before the system is ready.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-errors/workflow-world-error
|
|
8
|
+
- /docs/api-reference/workflow-errors/throttle-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`TooEarlyError` is thrown by world implementations when a request is made before the system is ready to process it. It corresponds to HTTP 425 Too Early semantics.
|
|
12
|
+
|
|
13
|
+
The `retryAfter` property contains the number of seconds to wait before retrying.
|
|
14
|
+
|
|
15
|
+
<Callout>
|
|
16
|
+
The Workflow runtime handles this error automatically by retrying after the specified delay. You will only encounter it when interacting with world storage APIs directly.
|
|
17
|
+
</Callout>
|
|
18
|
+
|
|
19
|
+
```typescript lineNumbers
|
|
20
|
+
import { TooEarlyError } from "workflow/errors"
|
|
21
|
+
declare const world: { events: { create(...args: any[]): Promise<any> } }; // @setup
|
|
22
|
+
declare const runId: string; // @setup
|
|
23
|
+
declare const event: any; // @setup
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await world.events.create(runId, event);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (TooEarlyError.is(error)) { // [!code highlight]
|
|
29
|
+
console.log(`Retry after ${error.retryAfter} seconds`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API Signature
|
|
35
|
+
|
|
36
|
+
### Properties
|
|
37
|
+
|
|
38
|
+
<TSDoc
|
|
39
|
+
definition={`
|
|
40
|
+
interface TooEarlyError {
|
|
41
|
+
/** Delay in seconds before the operation can be retried. Present when the server sends a Retry-After header. */
|
|
42
|
+
retryAfter?: number;
|
|
43
|
+
/** The error message. */
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
export default TooEarlyError;`}
|
|
47
|
+
/>
|
|
48
|
+
|
|
49
|
+
### Static Methods
|
|
50
|
+
|
|
51
|
+
#### `TooEarlyError.is(value)`
|
|
52
|
+
|
|
53
|
+
Type-safe check for `TooEarlyError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { TooEarlyError } from "workflow/errors"
|
|
57
|
+
declare const error: unknown; // @setup
|
|
58
|
+
|
|
59
|
+
if (TooEarlyError.is(error)) {
|
|
60
|
+
// error is typed as TooEarlyError
|
|
61
|
+
}
|
|
62
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WorkflowNotRegisteredError
|
|
3
|
+
description: Thrown when a workflow function is not registered in the current deployment.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch WorkflowNotRegisteredError when a workflow function cannot be found during execution.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/errors/workflow-not-registered
|
|
8
|
+
- /docs/api-reference/workflow-errors/step-not-registered-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`WorkflowNotRegisteredError` is thrown when the runtime tries to execute a workflow function that is not registered in the current deployment. This is an infrastructure error — not a user code error. It typically means a run was started against a deployment that does not have this workflow (e.g., the workflow was renamed or moved), or there was a build/bundling issue.
|
|
12
|
+
|
|
13
|
+
When this error occurs, the run fails with a `RUNTIME_ERROR` error code.
|
|
14
|
+
|
|
15
|
+
```typescript lineNumbers
|
|
16
|
+
import { WorkflowNotRegisteredError } from "workflow/errors"
|
|
17
|
+
declare const error: unknown; // @setup
|
|
18
|
+
|
|
19
|
+
if (WorkflowNotRegisteredError.is(error)) { // [!code highlight]
|
|
20
|
+
console.error("Workflow not registered:", error.workflowName);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API Signature
|
|
25
|
+
|
|
26
|
+
### Properties
|
|
27
|
+
|
|
28
|
+
<TSDoc
|
|
29
|
+
definition={`
|
|
30
|
+
interface WorkflowNotRegisteredError {
|
|
31
|
+
/** The name of the workflow function that was not found. */
|
|
32
|
+
workflowName: string;
|
|
33
|
+
/** The error message. */
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
export default WorkflowNotRegisteredError;`}
|
|
37
|
+
/>
|
|
38
|
+
|
|
39
|
+
### Static Methods
|
|
40
|
+
|
|
41
|
+
#### `WorkflowNotRegisteredError.is(value)`
|
|
42
|
+
|
|
43
|
+
Type-safe check for `WorkflowNotRegisteredError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
44
|
+
|
|
45
|
+
<Callout>
|
|
46
|
+
The `.is()` method works in server-side Node.js code (API routes, middleware). When checking the error from `run.returnValue`, use `WorkflowRunFailedError.is()` and inspect `error.cause` — the underlying error is deserialized from the event log.
|
|
47
|
+
</Callout>
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { WorkflowNotRegisteredError } from "workflow/errors"
|
|
51
|
+
declare const error: unknown; // @setup
|
|
52
|
+
|
|
53
|
+
if (WorkflowNotRegisteredError.is(error)) {
|
|
54
|
+
// error is typed as WorkflowNotRegisteredError
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WorkflowRunCancelledError
|
|
3
|
+
description: Thrown when awaiting the return value of a cancelled workflow run.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch WorkflowRunCancelledError when awaiting run.returnValue on a run that was cancelled.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-errors/workflow-run-failed-error
|
|
8
|
+
- /docs/api-reference/workflow-errors/workflow-run-not-found-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`WorkflowRunCancelledError` is thrown when awaiting `run.returnValue` on a workflow run that was explicitly cancelled via `run.cancel()`. Cancelled runs do not produce a return value.
|
|
12
|
+
|
|
13
|
+
You can check for cancellation before awaiting by inspecting `run.status`.
|
|
14
|
+
|
|
15
|
+
```typescript lineNumbers
|
|
16
|
+
import { WorkflowRunCancelledError } from "workflow/errors"
|
|
17
|
+
declare const run: { status: Promise<string>; returnValue: Promise<any> }; // @setup
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const result = await run.returnValue;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (WorkflowRunCancelledError.is(error)) { // [!code highlight]
|
|
23
|
+
console.log(`Run ${error.runId} was cancelled`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Signature
|
|
29
|
+
|
|
30
|
+
### Properties
|
|
31
|
+
|
|
32
|
+
<TSDoc
|
|
33
|
+
definition={`
|
|
34
|
+
interface WorkflowRunCancelledError {
|
|
35
|
+
/** The ID of the cancelled run. */
|
|
36
|
+
runId: string;
|
|
37
|
+
/** The error message. */
|
|
38
|
+
message: string;
|
|
39
|
+
}
|
|
40
|
+
export default WorkflowRunCancelledError;`}
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
### Static Methods
|
|
44
|
+
|
|
45
|
+
#### `WorkflowRunCancelledError.is(value)`
|
|
46
|
+
|
|
47
|
+
Type-safe check for `WorkflowRunCancelledError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { WorkflowRunCancelledError } from "workflow/errors"
|
|
51
|
+
declare const error: unknown; // @setup
|
|
52
|
+
|
|
53
|
+
if (WorkflowRunCancelledError.is(error)) {
|
|
54
|
+
// error is typed as WorkflowRunCancelledError
|
|
55
|
+
}
|
|
56
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WorkflowRunFailedError
|
|
3
|
+
description: Thrown when awaiting the return value of a failed workflow run.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch WorkflowRunFailedError when awaiting run.returnValue on a run that encountered a fatal error.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow/fatal-error
|
|
8
|
+
- /docs/api-reference/workflow-errors/workflow-run-cancelled-error
|
|
9
|
+
- /docs/api-reference/workflow-errors/workflow-run-not-found-error
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
`WorkflowRunFailedError` is thrown when awaiting `run.returnValue` on a workflow run whose status is `'failed'`. This indicates that the workflow encountered a fatal error during execution and cannot produce a return value.
|
|
13
|
+
|
|
14
|
+
The `cause` property contains the underlying error with its message, stack trace, and optional error code.
|
|
15
|
+
|
|
16
|
+
```typescript lineNumbers
|
|
17
|
+
import { WorkflowRunFailedError } from "workflow/errors"
|
|
18
|
+
declare const run: { status: Promise<string>; returnValue: Promise<any> }; // @setup
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const result = await run.returnValue;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (WorkflowRunFailedError.is(error)) { // [!code highlight]
|
|
24
|
+
console.error(`Run ${error.runId} failed:`, error.cause.message);
|
|
25
|
+
if (error.cause.code) {
|
|
26
|
+
console.error("Error code:", error.cause.code);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## API Signature
|
|
33
|
+
|
|
34
|
+
### Properties
|
|
35
|
+
|
|
36
|
+
<TSDoc
|
|
37
|
+
definition={`
|
|
38
|
+
interface WorkflowRunFailedError {
|
|
39
|
+
/** The ID of the failed run. */
|
|
40
|
+
runId: string;
|
|
41
|
+
/** The underlying error that caused the failure. */
|
|
42
|
+
cause: Error & { code?: string };
|
|
43
|
+
/** The error message. */
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
export default WorkflowRunFailedError;`}
|
|
47
|
+
/>
|
|
48
|
+
|
|
49
|
+
### Static Methods
|
|
50
|
+
|
|
51
|
+
#### `WorkflowRunFailedError.is(value)`
|
|
52
|
+
|
|
53
|
+
Type-safe check for `WorkflowRunFailedError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { WorkflowRunFailedError } from "workflow/errors"
|
|
57
|
+
declare const error: unknown; // @setup
|
|
58
|
+
|
|
59
|
+
if (WorkflowRunFailedError.is(error)) {
|
|
60
|
+
// error is typed as WorkflowRunFailedError
|
|
61
|
+
}
|
|
62
|
+
```
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WorkflowRunNotFoundError
|
|
3
|
+
description: Thrown when operating on a workflow run that does not exist.
|
|
4
|
+
type: reference
|
|
5
|
+
summary: Catch WorkflowRunNotFoundError when performing operations on a non-existent workflow run.
|
|
6
|
+
related:
|
|
7
|
+
- /docs/api-reference/workflow-errors/workflow-run-failed-error
|
|
8
|
+
- /docs/api-reference/workflow-errors/workflow-run-cancelled-error
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`WorkflowRunNotFoundError` is thrown when performing operations on a workflow run that does not exist. This includes calling methods like `run.status`, `run.cancel()`, or awaiting `run.returnValue` on a run whose ID does not match any known workflow run.
|
|
12
|
+
|
|
13
|
+
Note that `getRun(id)` itself is synchronous and will not throw — the error is raised when subsequent operations on the run object discover the run is missing.
|
|
14
|
+
|
|
15
|
+
```typescript lineNumbers
|
|
16
|
+
import { WorkflowRunNotFoundError } from "workflow/errors"
|
|
17
|
+
declare const run: { status: Promise<string>; returnValue: Promise<any> }; // @setup
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const status = await run.status;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (WorkflowRunNotFoundError.is(error)) { // [!code highlight]
|
|
23
|
+
console.error(`Run ${error.runId} does not exist`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## API Signature
|
|
29
|
+
|
|
30
|
+
### Properties
|
|
31
|
+
|
|
32
|
+
<TSDoc
|
|
33
|
+
definition={`
|
|
34
|
+
interface WorkflowRunNotFoundError {
|
|
35
|
+
/** The ID of the run that was not found. */
|
|
36
|
+
runId: string;
|
|
37
|
+
/** The error message. */
|
|
38
|
+
message: string;
|
|
39
|
+
}
|
|
40
|
+
export default WorkflowRunNotFoundError;`}
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
### Static Methods
|
|
44
|
+
|
|
45
|
+
#### `WorkflowRunNotFoundError.is(value)`
|
|
46
|
+
|
|
47
|
+
Type-safe check for `WorkflowRunNotFoundError` instances. Preferred over `instanceof` because it works across module boundaries and VM contexts.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { WorkflowRunNotFoundError } from "workflow/errors"
|
|
51
|
+
declare const error: unknown; // @setup
|
|
52
|
+
|
|
53
|
+
if (WorkflowRunNotFoundError.is(error)) {
|
|
54
|
+
// error is typed as WorkflowRunNotFoundError
|
|
55
|
+
}
|
|
56
|
+
```
|