-
Notifications
You must be signed in to change notification settings - Fork 512
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
Add validation for recurrence rules #122
Conversation
+1 from me. Solves existing issues, I'm for it... |
return true; | ||
}; | ||
|
||
RecurrenceRule.prototype.nextInvocationDate = function(base) { | ||
if (!this.validate()) { | ||
throw new Error('Invalid RecurrenceRule'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would we great that validate also returned info about what field is invalid. Then we could throw and error with a message like this: Invalid RecurrenceRule. Field year is out of range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@santigimeno Good idea. I'll add this.
I'll update this later today. |
@tejasmanohar @santigimeno see if this is better |
In the tests we should check that the error message is the expected. |
@santigimeno Good call. I'll add the checks. |
LGTM now. What about you, @santigimeno ? |
@jonhester Why are you validating at the beginning of every invocation. Wouldn't just validate once at scheduling suffice? |
@santigimeno You are correct that this is not ideal, but since nextInvocation is exposed as part of the api, this seems to me to be the only way to ensure that RecurrenceRule will always get validated. Something that should definitely be accounted for in a refactor. Check the RecurrenceRule tests to see what I mean. Here is an example from the first recurrence rule test:
|
Why dont you add a |
That could be done but could still not catch the error if someone does this:
Which is abusing the API for sure, but it's possible. |
Yeah, I see... still, I think we should not be validating in every invocation when scheduling a job. What about validating in the |
Still one could abuse the schedule API too, so I don't really know. |
@santigimeno Yeah, any way you cut it there is going to have to be a major refactor to fix this the right way. I think your idea is a good compromise to be able to go ahead and implement this. As we are working on the next major version we should make sure we account for this sort of thing. |
@santigimeno @tejasmanohar Should we hold this over until the next major version when we can validate in a way that's not a hack, or do you think it's worth implementing in the current version? |
@jonhester My vote is validate in a way that's not a hack and wait for 1.0. What's yours + @santigimeno? We can just go w/ majority. |
Yep. I would wait too |
Then, we'll re-open this when the time comes? |
Yeah, there's no possible way to do it correctly now. But working on this made me a lot more familiar with some of the issues and limitations of the current version so I think it was still worth my time. Sent from my iPhone
|
This takes care of #108 and will prevent things like #121 from happening. Throws error if not valid. Validation runs at the beginning of next invocation. @tejasmanohar and @santigimeno, what do you think?