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

error handling #426

Open
Tracked by #674
ks-s-a opened this issue Jun 11, 2019 · 10 comments · May be fixed by #861
Open
Tracked by #674

error handling #426

ks-s-a opened this issue Jun 11, 2019 · 10 comments · May be fixed by #861
Labels
good first issue Good for newcomers hacktoberfest This issue is registered for Hacktoberfest! help wanted Extra attention is needed status:ready Ready to start implementation type:feature New feature or feature improvement & requests

Comments

@ks-s-a
Copy link

ks-s-a commented Jun 11, 2019

Hello.

Is there a way to catch an error during the cronjob execution? As I see cron.start() doesn't return promise, so we can't just hang a .catch() there.

I guess it's common need so some people found a good approach to solve it.

Thank you a lot!

Feature specification: #426 (comment)

@magician11
Copy link

This is important.

If an error is thrown by a async function inside the cronjob callback.. then even with a try.. catch I will get

(node:8637) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

@ncb000gt
Copy link
Member

Currently there isn't a way. But, I do see value in this. If I get some time I'll implement this, otherwise I'd happily review a PR for this.

Thanks for bringing it up.

@tbasim
Copy link

tbasim commented May 31, 2020

Any updates on this?

@sathisa
Copy link

sathisa commented Jun 12, 2020

any update on this?

@chrisbrocklesby
Copy link

This would be VERY handy.... +1

@thiagodpf
Copy link

The palliative solution I found was to retrieve the CronJob callback list (job._callbacks) and for each spawn object (child_process) within it, add an handler to the spawn 'error' event, so I can at least be notified that something has gone wrong in the child_process ...

var job = new CronJob(/* parameters for the constructor */);

/* In practice you will only have one spawn to execute at each tick */
job._callbacks.forEach((spawn) => {
    spawn.on('error', (err) => {
        console.error('Failed to start subprocess.');
    });
});

You can do the same gambling on job.onComplete, as it turns into a spawn after all.

I am not proud to share this tip, but as long as there is no other solution, it goes anyway.

@NiekBeijloos
Copy link

What is the status of this feature? I noticed throwing an exception from the callback function given to cron.schedule will not terminate the overall process, but it just keeps executing. Does the node cron module apply a try catch under the hood or how can this behavior be explained?

@sheerlox sheerlox added the type:feature New feature or feature improvement & requests label Sep 26, 2023
@sheerlox sheerlox reopened this Sep 26, 2023
@sheerlox sheerlox changed the title Error handling [FEATURE] error handling Sep 28, 2023
@sheerlox sheerlox added Type: Feature Request type:feature New feature or feature improvement & requests and removed type:feature New feature or feature improvement & requests type:feature-request labels Sep 30, 2023
@sheerlox sheerlox changed the title [FEATURE] error handling error handling Sep 30, 2023
@sheerlox sheerlox added the status:requirements Full requirements are not yet known, so implementation should not be started label Sep 30, 2023
@sheerlox
Copy link
Collaborator

this feature's scope seems simple and well-defined enough:

  • add an optional parameter to CronJob to provide an error-handling function
  • catch any error happening in the callbacks (even if no error-hander was provided)
  • if an error handler was provided, call it with the error

@intcreator intcreator added hacktoberfest This issue is registered for Hacktoberfest! status:ready Ready to start implementation and removed status:requirements Full requirements are not yet known, so implementation should not be started labels Oct 2, 2023
@sheerlox sheerlox added help wanted Extra attention is needed good first issue Good for newcomers labels Oct 12, 2023
@JosephVoid
Copy link

JosephVoid commented Mar 2, 2024

Hi @sheerlox @ncb000gt,
I would like to add this feature.

@JosephVoid JosephVoid linked a pull request Mar 3, 2024 that will close this issue
9 tasks
@sheerlox
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest This issue is registered for Hacktoberfest! help wanted Extra attention is needed status:ready Ready to start implementation type:feature New feature or feature improvement & requests
Projects
None yet
Development

Successfully merging a pull request may close this issue.