mojombo / chronic

Chronic is a pure Ruby natural language date parser.
http://injekt.github.com/chronic
MIT License
3.23k stars 452 forks source link

Crash: Undefined method '+' for nil:Nilclass #370

Open bramski opened 6 years ago

bramski commented 6 years ago
NoMethodError (undefined method `+' for nil:NilClass):
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/repeaters/repeater_minute.rb:48:in `offset'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/handlers.rb:431:in `handle_srp'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/handlers.rb:457:in `handle_s_r_a_s_r_p_a'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/handler.rb:76:in `invoke'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/parser.rb:254:in `block in tokens_to_span'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/parser.rb:251:in `each'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/parser.rb:251:in `tokens_to_span'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic/parser.rb:61:in `parse'
/Users/bram/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/chronic-0.10.2/lib/chronic.rb:90:in `parse'

Failing on the string "26 of November 3 to 5"

davispuh commented 6 years ago

Such format isn't supported.

bramski commented 6 years ago

This much I know. But Chronic shouldn't crash my app. It's supposed to return nil if it can't parse it.

davispuh commented 6 years ago

Yeah, that's why it's also a bug but there are a lot of inputs which could crash it, you should catch those exceptions even if Chronic would be 100% safe.