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

require 'chronic' causes a LoadError #48

Closed
HerbCSO opened this issue Mar 10, 2015 · 1 comment · Fixed by #50
Closed

require 'chronic' causes a LoadError #48

HerbCSO opened this issue Mar 10, 2015 · 1 comment · Fixed by #50

Comments

@HerbCSO
Copy link

HerbCSO commented Mar 10, 2015

When passing in a Date argument, there is now code on line 435 that says require 'chronic'. Since trollop by design doesn't have dependencies, this is supposed to not cause an issue if the code using trollop doesn't have the chronic gem loaded. It used to be that there was no require there and this worked fine, because the NameError that would be triggered by the next line (time = Chronic.parse(param)) was rescued and everything would continue to work.

Sample setup:

  • Make a directory test_trollop_date
  • Make a Gemfile containing:
source 'https://rubygems.org'

gem 'trollop', '2.1.1'
  • Write a script test_trollop_date.rb with contents:
require 'trollop'

opts = Trollop::options do
  opt :date, 'Date', :type => :date, :required => true
end
  • Run bundle install
  • Run bundle exec ruby ./test_trollop_date.rb -d 2011-02-01

You'll get the following error:

/Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:435:in `require': cannot load such file -- chronic (LoadError)
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:435:in `parse_date_parameter'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:401:in `block (3 levels) in parse'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:401:in `map'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:401:in `block (2 levels) in parse'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:401:in `map'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:401:in `block in parse'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:378:in `each'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:378:in `parse'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:742:in `block in options'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:772:in `with_standard_exception_handling'
        from /Users/carsten.dreesbach/.rvm/gems/ruby-1.9.3-p550/gems/trollop-2.1.1/lib/trollop.rb:742:in `options'
        from ./test_trollop_date.rb:3:in `<main>'

The line require 'chronic' should therefore be removed, or you should also catch the LoadError.

@HerbCSO
Copy link
Author

HerbCSO commented Mar 10, 2015

Awesome, thanks @kbrock - any idea yet when the next release of trollop is likely to come out that will include this fix?

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 a pull request may close this issue.

1 participant