From da08e5015f297d21619aa45190fafd0b0ca460dd Mon Sep 17 00:00:00 2001 From: nicktrn <55853254+nicktrn@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:23:47 +0000 Subject: [PATCH] Pass init output to all error handlers (#1441) * pass init output to all error handlers * add changeset --- .changeset/cold-laws-float.md | 5 +++++ packages/core/src/v3/types/tasks.ts | 15 ++++++++------- packages/core/src/v3/workers/taskExecutor.ts | 4 ++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 .changeset/cold-laws-float.md diff --git a/.changeset/cold-laws-float.md b/.changeset/cold-laws-float.md new file mode 100644 index 0000000000..ffedfdd706 --- /dev/null +++ b/.changeset/cold-laws-float.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/core": patch +--- + +Pass init output to both local and global `handleError` functions diff --git a/packages/core/src/v3/types/tasks.ts b/packages/core/src/v3/types/tasks.ts index 394dde4458..df913ed0b4 100644 --- a/packages/core/src/v3/types/tasks.ts +++ b/packages/core/src/v3/types/tasks.ts @@ -127,6 +127,7 @@ export type HandleErrorResult = export type HandleErrorArgs = { ctx: Context; + init: unknown; retry?: RetryOptions; retryAt?: Date; retryDelayInMs?: number; @@ -152,9 +153,9 @@ type CommonTaskOptions< /** The retry settings when an uncaught error is thrown. * * If omitted it will use the values in your `trigger.config.ts` file. - * + * * @example - * + * * ``` * export const taskWithRetries = task({ id: "task-with-retries", @@ -174,10 +175,10 @@ type CommonTaskOptions< retry?: RetryOptions; /** Used to configure what should happen when more than one run is triggered at the same time. - * - * @example + * + * @example * one at a time execution - * + * * ```ts * export const oneAtATime = task({ id: "one-at-a-time", @@ -192,9 +193,9 @@ type CommonTaskOptions< */ queue?: QueueOptions; /** Configure the spec of the machine you want your task to run on. - * + * * @example - * + * * ```ts * export const heavyTask = task({ id: "heavy-task", diff --git a/packages/core/src/v3/workers/taskExecutor.ts b/packages/core/src/v3/workers/taskExecutor.ts index 98c6861c03..e927db9612 100644 --- a/packages/core/src/v3/workers/taskExecutor.ts +++ b/packages/core/src/v3/workers/taskExecutor.ts @@ -176,6 +176,7 @@ export class TaskExecutor { runError, parsedPayload, ctx, + initOutput, signal ); @@ -498,6 +499,7 @@ export class TaskExecutor { error: unknown, payload: any, ctx: TaskRunContext, + init: unknown, signal?: AbortSignal ): Promise< | { status: "retry"; retry: TaskRunExecutionRetry; error?: unknown } @@ -550,6 +552,7 @@ export class TaskExecutor { const handleErrorResult = this.task.fns.handleError ? await this.task.fns.handleError(payload, error, { ctx, + init, retry, retryDelayInMs: delay, retryAt: delay ? new Date(Date.now() + delay) : undefined, @@ -558,6 +561,7 @@ export class TaskExecutor { : this._importedConfig ? await this._handleErrorFn?.(payload, error, { ctx, + init, retry, retryDelayInMs: delay, retryAt: delay ? new Date(Date.now() + delay) : undefined,