trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

feat: support async `io.runTask` error callback

Open minyoung opened this issue 1 year ago • 1 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

minyoung avatar Feb 23 '24 20:02 minyoung

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

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

pnoyens avatar May 22 '24 14:05 pnoyens