Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Invalid ruby in Gemfile raises confusing error #5380

Closed
wintersolutions opened this issue Jan 29, 2017 · 8 comments
Closed

Invalid ruby in Gemfile raises confusing error #5380

wintersolutions opened this issue Jan 29, 2017 · 8 comments
Assignees

Comments

@wintersolutions
Copy link

Error Report

Questions

Please fill out answers to these questions, it'll help us figure out
why things are going wrong.

  • What did you do?

    I ran the command /home/foo_user/.rvm/gems/ruby-2.3.3@foo_project/bin/bundle update

  • What did you expect to happen?

    I expected Bundler to update the gems. Because this fails, I wanted Bundler to give me a name for the Gem that has illformed requirements or a linenumber in my Gemfile to identify the root cause.

  • What happened instead?

    Instead, what happened was that bundler quit with an error.

  • Have you tried any solutions posted on similar issues in our issue tracker, stack overflow, or google?

    I tried to:

    • find illformed requirement
    • update rubygems package with gem update --system
    • downgrade to bundler 13.x, which works
  • Have you read our issues document, https://github.com/bundler/bundler/blob/master/ISSUES.md?

Tried to, but gitbhub it gives me a 404.
...

Backtrace

Gem::Requirement::BadRequirementError: Illformed requirement ["~> 2.3.3\n.0"]
  /home/foo_user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/requirement.rb:101:in `parse'
  /home/foo_user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/requirement.rb:131:in `block in initialize'
  /home/foo_user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/requirement.rb:131:in `map!'
  /home/foo_user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/requirement.rb:131:in `initialize'
  /home/foo_user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/requirement.rb:59:in `new'
  /home/foo_user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/requirement.rb:59:in `create'
  /home/foo_user/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:59:in `initialize'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/dependency.rb:81:in `initialize'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/definition.rb:798:in `new'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/definition.rb:798:in `expanded_dependencies'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/definition.rb:252:in `resolve'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/definition.rb:176:in `specs'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/definition.rb:164:in `resolve_remotely!'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/installer.rb:226:in `resolve_if_need'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/installer.rb:78:in `run'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/installer.rb:24:in `install'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/cli/update.rb:55:in `run'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/cli.rb:221:in `update'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/cli.rb:20:in `dispatch'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/cli.rb:11:in `start'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/exe/bundle:32:in `block in <top (required)>'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
  /home/foo_user/.rvm/gems/ruby-2.3.3@global/gems/bundler-1.14.3/exe/bundle:24:in `<top (required)>'
  /home/foo_user/.rvm/gems/ruby-2.3.3@foo_project/bin/bundle:22:in `load'
  /home/foo_user/.rvm/gems/ruby-2.3.3@foo_project/bin/bundle:22:in `<main>'
  /home/foo_user/.rvm/gems/ruby-2.3.3@foo_project/bin/ruby_executable_hooks:15:in `eval'
  /home/foo_user/.rvm/gems/ruby-2.3.3@foo_project/bin/ruby_executable_hooks:15:in `<main>'

Environment

Bundler   1.14.3
Rubygems  2.6.9
Ruby      2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
GEM_HOME  /home/foo_user/.rvm/gems/ruby-2.3.3@foo_project
GEM_PATH  /home/foo_user/.rvm/gems/ruby-2.3.3@foo_project:/home/foo_user/.rvm/gems/ruby-2.3.3@global
RVM       1.28.0 (master)
Git       2.11.0
Platform  x86_64-linux
OpenSSL   OpenSSL 1.0.2j  26 Sep 2016
rubygems-bundler (1.4.4)

Bundler settings

local.foo  Set for the current user (/home/foo_user/.bundle/config): "/home/foo_user/projects/foo-common"
@segiddins
Copy link
Member

Please share your Gemfile so we can attempt to reproduce the issue?

@wintersolutions
Copy link
Author

wintersolutions commented Jan 29, 2017

Here is my Gemfile:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
  "https://github.com/#{repo_name}.git"
end

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'activerecord-import'
gem 'awesome_print'
gem 'bootstrap', '~> 4.0.0.alpha6'
gem 'cells-hamlit', platforms: :ruby
gem 'cells-rails'
gem 'devise'
gem 'flutie'
gem 'hamlit-block', platforms: :ruby
gem 'hamlit-rails'
# languages
gem 'mini_racer' if RUBY_PLATFORM =~ /linux/i
gem 'money-rails'
gem 'pry-rails'
gem 'rails-i18n'
gem 'rchardet'
gem 'redcarpet'
gem 'rfc5646'
gem 'seed-fu'
gem 'simple_form'
# Thor > 0.19.1 print warnings on rails g etc. see https://github.com/erikhuda/thor/issues/538
gem 'thor', '0.19.1'
gem 'trailblazer-cells'
gem 'trailblazer-rails'

source 'https://rails-assets.org' do
  # required by bootstrap tooltips
  gem 'rails-assets-tether'
end

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platform: :mri
  gem 'pry-byebug', platform: :mri
end

group :development do
  gem 'letter_opener'
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-commands-rspec'
  gem 'spring-watcher-listen', '~> 2.0.0'
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

group :test do
  gem 'brakeman', require: false
  gem 'bundler-audit', require: false
  gem 'capybara'
  gem 'factory_girl_rails'
  gem 'haml-lint', require: false
  gem 'rails-controller-testing'
  gem 'rspec-cells'
  gem 'rspec-rails'
  gem 'rubocop', require: false
  gem 'rubocop-rspec', require: false
  gem 'scss_lint', require: false
  gem 'shoulda-matchers'
  gem 'simplecov', require: false
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

ruby File.readlines('.ruby-version').first[5, 7]

The last line (ruby version) would contain 2.3.3 currently. Actual ruby version is ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]

Thanks for looking into it. Please let me know if I can help you with anything!

@mvz
Copy link
Contributor

mvz commented Jan 29, 2017

@wintersolutions I'm pretty sure that the last line is the cause of your problem. I also think you can achieve what you want by using ruby RUBY_VERSION instead.

@wintersolutions
Copy link
Author

wintersolutions commented Jan 29, 2017

@mvz you are right, works perfectly now. Idk why I did not see it because its kinda obvious now, especially since I wrote out what it does. Thanks a lot!

I use ruby File.readlines('.ruby-version').first[5, 7].strip now. I don't think I can use ruby RUBY_VERSION since it won't work on heroku...

@segiddins
Copy link
Member

We should definitely have a better error message for this, thanks for bringing it to our attention!

@segiddins segiddins reopened this Jan 29, 2017
@segiddins segiddins changed the title Version 1.14.3 exits when requirements are illformed Invalid ruby in Gemfile raises confusing error Jan 29, 2017
@segiddins
Copy link
Member

Can you share the contents of File.read(".ruby-version").dump though, so we can write a test?

@segiddins
Copy link
Member

segiddins commented Jan 29, 2017

diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index ebdefe63f..6fd65b5c1 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -21,7 +21,7 @@ module Bundler
       #   must not be specified, or the engine version
       #   specified must match the version.
 
-      @versions           = Array(versions)
+      @versions           = Array(versions).map {|v| Gem::Requirement.parse(v).last }
       @gem_version        = Gem::Requirement.create(@versions.first).requirements.first.last
       @input_engine       = engine && engine.to_s
       @engine             = engine && engine.to_s || "ruby"
diff --git a/spec/install/gemfile/ruby_spec.rb b/spec/install/gemfile/ruby_spec.rb
index 3f8957916..cff338429 100644
--- a/spec/install/gemfile/ruby_spec.rb
+++ b/spec/install/gemfile/ruby_spec.rb
@@ -86,4 +86,24 @@ RSpec.describe "ruby requirement" do
     expect(the_bundle).to include_gems "rack 1.0.0"
     expect(locked_ruby_version.versions).to eq(["5100"])
   end
+
+  it "allows requirements with trailing whitespace" do
+    install_gemfile! <<-G
+      source "file://#{gem_repo1}"
+      ruby "#{Gem.ruby_version}\\n \t\\n"
+      gem "rack"
+    G
+
+    expect(the_bundle).to include_gems "rack 1.0.0"
+  end
+
+  it "fails gracefully with malformed requirements" do
+    install_gemfile <<-G
+      source "file://#{gem_repo1}"
+      ruby ">= 0", "-.\\0"
+      gem "rack"
+    G
+
+    expect(out).to include("There was an error parsing") # i.e. DSL error, not error template
+  end
 end

@wintersolutions
Copy link
Author

wintersolutions commented Jan 30, 2017

File.read(".ruby-version").dump
"\"ruby-2.3.3\\n\""

Here is the version file (zipped since github won't accept it otherwise):
ruby-version.zip

Thanks for your help and the improvement!

@segiddins segiddins self-assigned this Feb 1, 2017
bundlerbot added a commit that referenced this issue Feb 8, 2017
…ndirect

[RubyVersion] Ensure passed-in versions are valid during init

Closes #5380
bundlerbot added a commit that referenced this issue Feb 8, 2017
…ndirect

[RubyVersion] Ensure passed-in versions are valid during init

Closes #5380
segiddins pushed a commit that referenced this issue Feb 12, 2017
…ndirect

[RubyVersion] Ensure passed-in versions are valid during init

Closes #5380

(cherry picked from commit 427f07f)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants