triggerdotdev / trigger.dev

Trigger.dev is the open source background jobs platform for TypeScript.

Home Page:https://trigger.dev/changelog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: support async `io.runTask` error callback

minyoung opened this issue · comments

Is your feature request related to a problem? Please describe.

When io.runTask runs, it has an onError callback option. This is great!
But I have some async logic that I would like to run in this error callback. This is currently not supported since the error callback cannot return a promise.

Describe the solution you'd like to see

Update RunTaskErrorCallback type to allow returning a promise, and update io.runTask to await onError(error, task, this)

Describe alternate solutions

Do nothing and tell developers to try/catch inside the io.runTask (where it is async):

io.runTask(
  "name",
  async (task) => {
    try {
      // ...
    } catch (error) {
      await sendErrorNotification(payload)
    }
  },
)

Additional information

No response

Try wrapping your io.runTask inside this: https://trigger.dev/docs/sdk/io/try

The catchCallback that comes with this, supports async code :)