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

feat: error handling on ticks #861

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

JosephVoid
Copy link

@JosephVoid JosephVoid commented Mar 3, 2024

Description

I've added an error handling method in the CronJob class and added it to the constructors parameters. This error handling method will be called if any exception is thrown from the onTick method. Also added two new tests to confirm that it works.

Related Issue

Closes #426.

Motivation and Context

If any kind of exception occurs from the onTick method the whole process stops currently. To solve this, this feature will allow users to pass their own error handler when exceptions occur.

How Has This Been Tested?

Added two new test cases called should catch errors if errorhandler is provided & should throw errors if errorhandler is NOT provided

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • If my change introduces a breaking change, I have added a ! after the type/scope in the title (see the Conventional Commits standard).

+ added error handling function param on a new constructor
+ added the function param on the static `from` method
+ caught the errors in the callback method
+ removed `@ts-expect-error line` bc it was throwing error itself
@JosephVoid JosephVoid changed the title feat: error handling on job.start() feat(error-handle): error handling on job.start() Mar 3, 2024
@JosephVoid JosephVoid changed the title feat(error-handle): error handling on job.start() feat: error handling on job.start() Mar 3, 2024
@JosephVoid JosephVoid marked this pull request as ready for review March 3, 2024 09:45
src/types/cron.types.ts Outdated Show resolved Hide resolved
tests/cron.test.ts Outdated Show resolved Hide resolved
src/job.ts Show resolved Hide resolved
src/job.ts Outdated Show resolved Hide resolved
src/job.ts Outdated Show resolved Hide resolved
+ Instead of a new constructor, I added the `errorHandler` on every other constructor
+ removed the superflous if checks
+ added `errorHandler` on every `return new CronJob`
@JosephVoid
Copy link
Author

Hey @sheerlox,

Thanks for the review. I've incorporated all the suggestions.

Copy link
Collaborator

@sheerlox sheerlox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for your contribution @JosephVoid 🙌

@sheerlox sheerlox requested a review from intcreator March 8, 2024 09:13
@sheerlox sheerlox changed the title feat: error handling on job.start() feat: error handling on ticks Mar 8, 2024
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

Successfully merging this pull request may close these issues.

error handling
2 participants