Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown inside scheduled task is silently swallowed #399

Open
avillacis opened this issue Mar 7, 2023 · 3 comments
Open

Exception thrown inside scheduled task is silently swallowed #399

avillacis opened this issue Mar 7, 2023 · 3 comments

Comments

@avillacis
Copy link

If the function or closure passed as a parameter of the cron.schedule happens to throw an exception anywhere, and is not properly catched withing the body of the function, the library swallows the exception silently with no indication as to whether an exception has happened. This makes debugging more difficult.

The library should catch and dump the unhandled exception. Failing that, this caveat should be documented in the manual so the programmer can guard against it from the very start.

@Hexagon
Copy link

Hexagon commented Mar 12, 2023

Meanwhile, croner has an option to control this - (catch), which takes true to silently swallow, false to re-throw, or a callback function if you want to handle the error in a more controlled way. See https://github.com/Hexagon/croner/blob/master/docs/EXAMPLES.md#error-handling for an example

@zimmerry
Copy link

zimmerry commented May 11, 2023

I've also been running into this issue, I've spent a lot of time debugging one of my scheduled tasks that seemingly stopped in the middle of executing - turns out it was throwing an exception and just stopping.

@samuliasmala
Copy link

I did a workaround for async tasks by using a wrapper function:

function scheduleAsyncCron(expression, fn, options) {
  cron.schedule(expression, () => fn().catch((e) => console.error(e)), options);
}

scheduleAsyncCron('* * * * *', async () => {
  await asyncFunctionToRun();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants