Skip to content

Commit

Permalink
Pass init output to all error handlers (#1441)
Browse files Browse the repository at this point in the history
* pass init output to all error handlers

* add changeset
  • Loading branch information
nicktrn authored Oct 31, 2024
1 parent 9b74728 commit da08e50
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
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

0 comments on commit da08e50

Please sign in to comment.