Skip to content

Commit da08e50

Browse files
authored
Pass init output to all error handlers (#1441)
* pass init output to all error handlers * add changeset
1 parent 9b74728 commit da08e50

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

.changeset/cold-laws-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/core": patch
3+
---
4+
5+
Pass init output to both local and global `handleError` functions

packages/core/src/v3/types/tasks.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export type HandleErrorResult =
127127

128128
export type HandleErrorArgs = {
129129
ctx: Context;
130+
init: unknown;
130131
retry?: RetryOptions;
131132
retryAt?: Date;
132133
retryDelayInMs?: number;
@@ -152,9 +153,9 @@ type CommonTaskOptions<
152153
/** The retry settings when an uncaught error is thrown.
153154
*
154155
* If omitted it will use the values in your `trigger.config.ts` file.
155-
*
156+
*
156157
* @example
157-
*
158+
*
158159
* ```
159160
* export const taskWithRetries = task({
160161
id: "task-with-retries",
@@ -174,10 +175,10 @@ type CommonTaskOptions<
174175
retry?: RetryOptions;
175176

176177
/** Used to configure what should happen when more than one run is triggered at the same time.
177-
*
178-
* @example
178+
*
179+
* @example
179180
* one at a time execution
180-
*
181+
*
181182
* ```ts
182183
* export const oneAtATime = task({
183184
id: "one-at-a-time",
@@ -192,9 +193,9 @@ type CommonTaskOptions<
192193
*/
193194
queue?: QueueOptions;
194195
/** Configure the spec of the machine you want your task to run on.
195-
*
196+
*
196197
* @example
197-
*
198+
*
198199
* ```ts
199200
* export const heavyTask = task({
200201
id: "heavy-task",

packages/core/src/v3/workers/taskExecutor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export class TaskExecutor {
176176
runError,
177177
parsedPayload,
178178
ctx,
179+
initOutput,
179180
signal
180181
);
181182

@@ -498,6 +499,7 @@ export class TaskExecutor {
498499
error: unknown,
499500
payload: any,
500501
ctx: TaskRunContext,
502+
init: unknown,
501503
signal?: AbortSignal
502504
): Promise<
503505
| { status: "retry"; retry: TaskRunExecutionRetry; error?: unknown }
@@ -550,6 +552,7 @@ export class TaskExecutor {
550552
const handleErrorResult = this.task.fns.handleError
551553
? await this.task.fns.handleError(payload, error, {
552554
ctx,
555+
init,
553556
retry,
554557
retryDelayInMs: delay,
555558
retryAt: delay ? new Date(Date.now() + delay) : undefined,
@@ -558,6 +561,7 @@ export class TaskExecutor {
558561
: this._importedConfig
559562
? await this._handleErrorFn?.(payload, error, {
560563
ctx,
564+
init,
561565
retry,
562566
retryDelayInMs: delay,
563567
retryAt: delay ? new Date(Date.now() + delay) : undefined,

0 commit comments

Comments
 (0)