Skip to content
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
8 changes: 4 additions & 4 deletions docs/config/config-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ import { defineConfig } from "@trigger.dev/sdk";
export default defineConfig({
project: "<project ref>",
// Your other config settings...
onSuccess: async (payload, output, { ctx }) => {
onSuccess: async ({ payload, output, ctx }) => {
console.log("Task succeeded", ctx.task.id);
},
onFailure: async (payload, error, { ctx }) => {
onFailure: async ({ payload, error, ctx }) => {
console.log("Task failed", ctx.task.id);
},
onStart: async (payload, { ctx }) => {
onStart: async ({ payload, ctx }) => {
console.log("Task started", ctx.task.id);
},
init: async (payload, { ctx }) => {
init: async ({ payload, ctx }) => {
console.log("I run before any task is run");
},
});
Expand Down
4 changes: 2 additions & 2 deletions docs/errors-retrying.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const taskWithFetchRetries = task({

## Advanced error handling and retrying

We provide a `handleError` callback on the task and in your `trigger.config` file. This gets called when an uncaught error is thrown in your task.
We provide a `catchError` callback on the task and in your `trigger.config` file. This gets called when an uncaught error is thrown in your task.

You can

Expand Down Expand Up @@ -219,7 +219,7 @@ export const openaiTask = task({

return chatCompletion.choices[0].message.content;
},
handleError: async (payload, error, { ctx, retryAt }) => {
catchError: async ({ payload, error, ctx, retryAt }) => {
if (error instanceof OpenAI.APIError) {
if (!error.status) {
return {
Expand Down
2 changes: 1 addition & 1 deletion docs/migrating-from-v3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ import { task } from "@trigger.dev/sdk";

export const myTask = task({
id: "my-task",
onStart: (payload, { ctx }) => {},
onStart: ({ payload, ctx }) => {},
run: async (payload, { ctx }) => {},
});
```
Expand Down
29 changes: 15 additions & 14 deletions docs/tasks/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ This function is called before a run attempt:
```ts /trigger/init.ts
export const taskWithInit = task({
id: "task-with-init",
init: async (payload, { ctx }) => {
init: async ({ payload, ctx }) => {
//...
},
run: async (payload: any, { ctx }) => {
Expand All @@ -195,7 +195,7 @@ You can also return data from the `init` function that will be available in the
```ts /trigger/init-return.ts
export const taskWithInitReturn = task({
id: "task-with-init-return",
init: async (payload, { ctx }) => {
init: async ({ payload, ctx }) => {
return { someData: "someValue" };
},
run: async (payload: any, { ctx, init }) => {
Expand All @@ -213,7 +213,7 @@ This function is called after the `run` function is executed, regardless of whet
```ts /trigger/cleanup.ts
export const taskWithCleanup = task({
id: "task-with-cleanup",
cleanup: async (payload, { ctx }) => {
cleanup: async ({ payload, ctx }) => {
//...
},
run: async (payload: any, { ctx }) => {
Expand All @@ -230,7 +230,7 @@ Our task middleware system runs at the top level, executing before and after all

<Info>
An error thrown in `middleware` is just like an uncaught error in the run function: it will
propagate through to `handleError()` and then will fail the attempt (causing a retry).
propagate through to `catchError()` function and then will fail the attempt (causing a retry).
</Info>

The `locals` API allows you to share data between middleware and hooks.
Expand Down Expand Up @@ -303,7 +303,7 @@ When a task run starts, the `onStart` function is called. It's useful for sendin
```ts /trigger/on-start.ts
export const taskWithOnStart = task({
id: "task-with-on-start",
onStart: async (payload, { ctx }) => {
onStart: async ({ payload, ctx }) => {
//...
},
run: async (payload: any, { ctx }) => {
Expand All @@ -319,7 +319,7 @@ import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
project: "proj_1234",
onStart: async (payload, { ctx }) => {
onStart: async ({ payload, ctx }) => {
console.log("Task started", ctx.task.id);
},
});
Expand Down Expand Up @@ -357,7 +357,7 @@ When a task run succeeds, the `onSuccess` function is called. It's useful for se
```ts /trigger/on-success.ts
export const taskWithOnSuccess = task({
id: "task-with-on-success",
onSuccess: async (payload, output, { ctx }) => {
onSuccess: async ({ payload, output, ctx }) => {
//...
},
run: async (payload: any, { ctx }) => {
Expand All @@ -373,7 +373,7 @@ import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
project: "proj_1234",
onSuccess: async (payload, output, { ctx }) => {
onSuccess: async ({ payload, output, ctx }) => {
console.log("Task succeeded", ctx.task.id);
},
});
Expand All @@ -388,7 +388,7 @@ This hook is executed when a run completes, regardless of whether it succeeded o
```ts /trigger/on-complete.ts
export const taskWithOnComplete = task({
id: "task-with-on-complete",
onComplete: async (payload, output, { ctx }) => {
onComplete: async ({ payload, output, ctx }) => {
if (result.ok) {
console.log("Run succeeded", result.data);
} else {
Expand All @@ -404,7 +404,7 @@ When a task run fails, the `onFailure` function is called. It's useful for sendi
```ts /trigger/on-failure.ts
export const taskWithOnFailure = task({
id: "task-with-on-failure",
onFailure: async (payload, error, { ctx }) => {
onFailure: async ({ payload, error, ctx }) => {
//...
},
run: async (payload: any, { ctx }) => {
Expand All @@ -420,7 +420,7 @@ import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
project: "proj_1234",
onFailure: async (payload, error, { ctx }) => {
onFailure: async ({ payload, error, ctx }) => {
console.log("Task failed", ctx.task.id);
},
});
Expand All @@ -429,14 +429,15 @@ export default defineConfig({
<Info>Errors thrown in the `onFailure` function are ignored.</Info>

<Note>
`onFailure` doesn’t fire for some of the run statuses like `Crashed`, `System failures`, and `Canceled`.
`onFailure` doesn’t fire for some of the run statuses like `Crashed`, `System failures`, and
`Canceled`.
</Note>

### `handleError` functions
### `catchError` functions

You can define a function that will be called when an error is thrown in the `run` function, that allows you to control how the error is handled and whether the task should be retried.

Read more about `handleError` in our [Errors and Retrying guide](/errors-retrying).
Read more about `catchError` in our [Errors and Retrying guide](/errors-retrying).

<Info>Uncaught errors will throw a special internal error of the type `HANDLE_ERROR_ERROR`.</Info>

Expand Down