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

invalid configuration causes app to explode #31

Closed
mfkp opened this issue Aug 11, 2015 · 2 comments
Closed

invalid configuration causes app to explode #31

mfkp opened this issue Aug 11, 2015 · 2 comments

Comments

@mfkp
Copy link

mfkp commented Aug 11, 2015

Just ran into this in my production system.

If you pass in an empty hours hash in config.hours, or if a single day has an empty hash, and you do something like:

biz = Biz::Schedule.new do |config|
  config.hours = {}
end
biz.periods
  .after(local_date.beginning_of_day)
  .timeline
  .forward
  .until(local_date.end_of_day)
  .to_a

then it'll spin forever and blow up your server.

This happened to me because I have subtractive hours, so sometimes it turns out that there can be no hours for a certain timeframe.

@craiglittle
Copy link
Collaborator

Hey, @mfkp!

One solution for your particular use case is to return early if the configuration is empty, avoiding the calls to biz entirely.

From the prospective of biz, given that methods like Biz::time would provide nonsensical results when provided an empty configuration, I think the solution to this issue is to raise a configuration validation error upfront at configuration time.

Does that seem reasonable?

@mfkp
Copy link
Author

mfkp commented Aug 11, 2015

Yeah, raising an error seems like a valid solution. Really, anything is better than melting the cpu 😄

Took me a while to track it down too, something loud like that would make it easier to find next time.

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

2 participants