rvm/rubygems-bundler

`rake foo` with an unmatched Gemfile dependency includes the full stacktrace, no "bundle install" suggestion

aprescott opened this issue · 3 comments

(I don't think this is specific to rake, but it's the original stimulus here.)

With an rvm-installed ruby and the bundler gem installed, here's a minimal reproduction showing what I mean:

mkdir -p /tmp/foo
cd /tmp/foo

echo 'source :rubygems

gem "sass", "= 99.9"' > Gemfile

rake foo

(The version of sass intentionally high to force a missing gem.)

From the $ rake foo command, there's a stacktrace as the output:

/home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/resolver.rb:287:in `resolve': Could not find gem 'sass (= 99.9) ruby' in the gems available on this machine. (Bundler::GemNotFound)
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/resolver.rb:161:in `start'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/resolver.rb:128:in `block in resolve'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/resolver.rb:127:in `catch'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/resolver.rb:127:in `resolve'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/definition.rb:192:in `resolve'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/definition.rb:127:in `specs'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/environment.rb:27:in `specs'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.2/lib/rubygems-bundler/noexec.rb:41:in `candidate?'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.2/lib/rubygems-bundler/noexec.rb:60:in `setup'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.2/lib/rubygems-bundler/noexec.rb:75:in `<top (required)>'
    from /home/adam/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
    from /home/adam/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
    from /home/adam/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
    from /home/adam/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:9:in `<main>'

Contrast that with the output from $ bundle exec rake foo:

Could not find gem 'sass (= 99.9) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.

To a user who is ignorant of Bundler, the stacktrace doesn't tell you how to fix it, despite it being very simple, whereas the bundle exec version makes it very clear. Since rubygems-bundler seems to intend to make the bundle exec redundant, and a missing gem dependency isn't such an exceptional case, I think it would be better to follow the simpler output instead of the stacktrace. (It also has the added bonus that to someone who doesn't yet fully understand how Bundler works, or when rake tasks are used as part of a non-Ruby project where Ruby ecosystem tools aren't assumed knowledge, it clearly tells you how to fix the problem immediately.)

Similar problem here: pry/pry#671

Please test with 1.0.7.

Looks good! (Also, apologies for the test case that wasn't actually complete. I only just realised it needed an echo $stuff > rakefile.)

Thanks for fixing.