Skip to content

Pass init output to all error handlers #1441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/cold-laws-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

Pass init output to both local and global `handleError` functions
15 changes: 8 additions & 7 deletions packages/core/src/v3/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export type HandleErrorResult =

export type HandleErrorArgs = {
ctx: Context;
init: unknown;
retry?: RetryOptions;
retryAt?: Date;
retryDelayInMs?: number;
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/v3/workers/taskExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class TaskExecutor {
runError,
parsedPayload,
ctx,
initOutput,
signal
);

Expand Down Expand Up @@ -498,6 +499,7 @@ export class TaskExecutor {
error: unknown,
payload: any,
ctx: TaskRunContext,
init: unknown,
signal?: AbortSignal
): Promise<
| { status: "retry"; retry: TaskRunExecutionRetry; error?: unknown }
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading