@@ -181,7 +181,7 @@ This function is called before a run attempt:
181181``` ts /trigger/init.ts
182182export const taskWithInit = task ({
183183 id: " task-with-init" ,
184- init : async (payload , { ctx }) => {
184+ init : async ({ payload , ctx }) => {
185185 // ...
186186 },
187187 run : async (payload : any , { ctx }) => {
@@ -195,7 +195,7 @@ You can also return data from the `init` function that will be available in the
195195``` ts /trigger/init-return.ts
196196export const taskWithInitReturn = task ({
197197 id: " task-with-init-return" ,
198- init : async (payload , { ctx }) => {
198+ init : async ({ payload , ctx }) => {
199199 return { someData: " someValue" };
200200 },
201201 run : async (payload : any , { ctx , init }) => {
@@ -213,7 +213,7 @@ This function is called after the `run` function is executed, regardless of whet
213213``` ts /trigger/cleanup.ts
214214export const taskWithCleanup = task ({
215215 id: " task-with-cleanup" ,
216- cleanup : async (payload , { ctx }) => {
216+ cleanup : async ({ payload , ctx }) => {
217217 // ...
218218 },
219219 run : async (payload : any , { ctx }) => {
@@ -230,7 +230,7 @@ Our task middleware system runs at the top level, executing before and after all
230230
231231<Info >
232232 An error thrown in ` middleware ` is just like an uncaught error in the run function: it will
233- propagate through to ` handleError ()` and then will fail the attempt (causing a retry).
233+ propagate through to ` catchError ()` function and then will fail the attempt (causing a retry).
234234</Info >
235235
236236The ` locals ` API allows you to share data between middleware and hooks.
@@ -303,7 +303,7 @@ When a task run starts, the `onStart` function is called. It's useful for sendin
303303``` ts /trigger/on-start.ts
304304export const taskWithOnStart = task ({
305305 id: " task-with-on-start" ,
306- onStart : async (payload , { ctx }) => {
306+ onStart : async ({ payload , ctx }) => {
307307 // ...
308308 },
309309 run : async (payload : any , { ctx }) => {
@@ -319,7 +319,7 @@ import { defineConfig } from "@trigger.dev/sdk";
319319
320320export default defineConfig ({
321321 project: " proj_1234" ,
322- onStart : async (payload , { ctx }) => {
322+ onStart : async ({ payload , ctx }) => {
323323 console .log (" Task started" , ctx .task .id );
324324 },
325325});
@@ -357,7 +357,7 @@ When a task run succeeds, the `onSuccess` function is called. It's useful for se
357357``` ts /trigger/on-success.ts
358358export const taskWithOnSuccess = task ({
359359 id: " task-with-on-success" ,
360- onSuccess : async (payload , output , { ctx }) => {
360+ onSuccess : async ({ payload , output , ctx }) => {
361361 // ...
362362 },
363363 run : async (payload : any , { ctx }) => {
@@ -373,7 +373,7 @@ import { defineConfig } from "@trigger.dev/sdk";
373373
374374export default defineConfig ({
375375 project: " proj_1234" ,
376- onSuccess : async (payload , output , { ctx }) => {
376+ onSuccess : async ({ payload , output , ctx }) => {
377377 console .log (" Task succeeded" , ctx .task .id );
378378 },
379379});
@@ -388,7 +388,7 @@ This hook is executed when a run completes, regardless of whether it succeeded o
388388``` ts /trigger/on-complete.ts
389389export const taskWithOnComplete = task ({
390390 id: " task-with-on-complete" ,
391- onComplete : async (payload , output , { ctx }) => {
391+ onComplete : async ({ payload , output , ctx }) => {
392392 if (result .ok ) {
393393 console .log (" Run succeeded" , result .data );
394394 } else {
@@ -404,7 +404,7 @@ When a task run fails, the `onFailure` function is called. It's useful for sendi
404404` ` ` ts / trigger / on - failure .ts
405405export const taskWithOnFailure = task ({
406406 id: " task-with-on-failure" ,
407- onFailure : async (payload , error , { ctx }) => {
407+ onFailure : async ({ payload , error , ctx }) => {
408408 // ...
409409 },
410410 run : async (payload : any , { ctx }) => {
@@ -420,7 +420,7 @@ import { defineConfig } from "@trigger.dev/sdk";
420420
421421export default defineConfig ({
422422 project: " proj_1234" ,
423- onFailure : async (payload , error , { ctx }) => {
423+ onFailure : async ({ payload , error , ctx }) => {
424424 console .log (" Task failed" , ctx .task .id );
425425 },
426426});
@@ -429,14 +429,15 @@ export default defineConfig({
429429<Info>Errors thrown in the ` onFailure ` function are ignored.</Info>
430430
431431<Note>
432- ` onFailure ` doesn’t fire for some of the run statuses like ` Crashed ` , ` System failures ` , and ` Canceled ` .
432+ ` onFailure ` doesn’t fire for some of the run statuses like ` Crashed ` , ` System failures ` , and
433+ ` Canceled ` .
433434</Note>
434435
435- ### ` handleError ` functions
436+ ### ` catchError ` functions
436437
437438You 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.
438439
439- Read more about ` handleError ` in our [Errors and Retrying guide](/errors-retrying).
440+ Read more about ` catchError ` in our [Errors and Retrying guide](/errors-retrying).
440441
441442<Info>Uncaught errors will throw a special internal error of the type ` HANDLE_ERROR_ERROR ` .</Info>
442443
0 commit comments