IO
io.try()
io.try()
allows you to run Tasks and catch any errors that are thrown, it’s similar to a normal try/catch
block but works with io.runTask().
These are the docs for Trigger.dev v2 which will be deprecated on January 31st, 2025. You probably want the v3 docs.
A regular try/catch
block on its own won’t work as expected with Tasks. Internally runTask()
throws some special errors to control flow execution. This is necessary to deal with resumability, serverless timeouts, and retrying Tasks.
How to catch
errors inside run()
You have two options:
- Use the
io.try()
function documented on this page. - Use a regular
try/catch
block and isTriggerError to check if the error is a special error type.
Parameters
The code you wish to run
This will be called if the Task fails. The callback receives the error
Returns
A Promise that resolves with the returned value or the error