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

No parsing error when passing an invalid cron expression to cron function #7

Open
naz opened this issue Nov 5, 2020 · 4 comments
Open

Comments

@naz
Copy link
Member

naz commented Nov 5, 2020

refs bunkat/later#174

Problem

As pointed out in referenced issue there is no error detection logic in later.parse.cron function. This introduced an inconsistency with how later.parse.text behave when invalid values are passed in. In case of cron method there is no indication of any type of error if completely invalid string is passed in. Contrary for text method there's error property assigned to returned object when the expression is not parsed.

Possible solution

There are multiple ways I can see this issue can be approached:

  1. Leave it as is, but be very specific that making sure the cron expression is valid is on the client
  2. Validate cron expression internally and return consistent error just like in case of parsing expression through text function

Personally I'm in favor of second approach as that would allow to unify error handling.

@naz
Copy link
Member Author

naz commented Nov 5, 2020

To move on with the implementation I've ended up using cron-parser to validate cron expressions before calling later.parse.cron. Might serve as a good reference for parsing logic

@naz
Copy link
Member Author

naz commented Nov 9, 2020

Had a look into what bree does with this exact problem and saw that it's running cron expression validation against cron-validate.

If the validation for cron expressions is moved into later's layer, I think it will make the logic for both cron and text expressions-to-schedule transformations more consistent.

@hovancik
Copy link

hovancik commented Feb 1, 2021

Just noticed the same issue. Would make sense to use same as for text parser as right now cron gives me 0 for error all the time and that complicates everything.

@arossert
Copy link

arossert commented Jun 23, 2024

I also noticed now that later is not validating cron strings, is there a plan to add this or do I need to validate it manually?

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

3 participants