Bundler 1.1.rc.7 crashes on buggy gem name #1672

Closed
korny opened this Issue Feb 23, 2012 · 11 comments

Comments

Projects
None yet
4 participants

korny commented Feb 23, 2012

Stupid me forgot a comma in my Gemfile:

gem "roadie"                  "~> 1.1.3"                                    # emails

This is obviously wrong, but it crashes the latest Bundler RC when I run "bundle":

Fetching gem metadata from http://rubygems.org/.Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Thanks!
/Users/murphy/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/uri/common.rb:436:in `split': bad URI(is not URI?): http://rubygems.org/api/v1/dependencies?gems=rails,rake,rdoc,json,mysql2,nokogiri,oily_png,raspell,RedCloth,prawn,prawn-core,prawn-layout,prawn-format,haml,sass,compass,thinking-sphinx,ts-delayed-delta,thinking-sphinx-raspell,validates_date_time,validates_existence,active_link_to,acts-as-taggable-on,aws-s3,BlueCloth,cancan,comma,deadlock_retry,delayed_job,directed-edge,fastercsv,google-spreadsheet-ruby,googlecharts,jquery-rails,jrails,panda,paperclip,rakismet,roadie~> 1.1.3,rubyzip,settingslogic,simple-rss,sitemap_generator,symbolize,system_timer,whenever,will_paginate,workflow,passenger,newrelic_rpm,airbrake,inaction_mailer,rails-dev-boost,capistrano,amazon-ec2,codebase4,rspec-rails,email_spec,factory_girl,cucumber,cucumber-rails,database_cleaner,capybara,akephalos,launchy,selenium-webdriver (URI::InvalidURIError)
    from /Users/murphy/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/uri/common.rb:485:in `parse'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/fetcher.rb:159:in `fetch_dependency_remote_specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/fetcher.rb:122:in `fetch_remote_specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/fetcher.rb:70:in `specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/source.rb:230:in `remote_specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/source.rb:228:in `each'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/source.rb:228:in `remote_specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/source.rb:161:in `fetch_specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/source.rb:70:in `specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/definition.rb:175:in `index'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/definition.rb:173:in `each'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/definition.rb:173:in `index'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/index.rb:7:in `build'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/definition.rb:161:in `index'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/definition.rb:155:in `resolve'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/definition.rb:90:in `specs'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/definition.rb:85:in `resolve_remotely!'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/installer.rb:48:in `run'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/installer.rb:12:in `install'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/cli.rb:220:in `install'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/vendor/thor/task.rb:22:in `send'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/vendor/thor.rb:263:in `dispatch'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/lib/bundler/vendor/thor/base.rb:386:in `start'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/gems/bundler-1.1.rc.7/bin/bundle:13
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/bin/bundle:19:in `load'
    from /Users/murphy/.rvm/gems/ree-1.8.7-2011.03@sofatutor/bin/bundle:19

The current release version (1.0.22) handles this gracefully:

Could not find gem 'roadie~> 1.1.3 (>= 0) ruby' in any of the gem sources listed in your Gemfile.

The URL is valid, but seemingly URI.parse doesn't like it.

eval commented Feb 23, 2012

You're missing a comma, I guess:

gem "roadie", "~> 1.1.3"

eval commented Feb 24, 2012

Stupid me, you already concluded that ;)

Contributor

rohit commented Mar 8, 2012

@eval Did you solve you're issue? If so can you please close this issue. Thanks!

eval commented Mar 8, 2012

@rohit let's ask @korny, the OP

korny commented Mar 8, 2012

1.1.0 still returns the same error message.

Contributor

rohit commented Mar 9, 2012

The fix seems simple. I'll check if it affects other parts of the code base and submit a pull request asap.

Contributor

rohit commented Mar 9, 2012

Actually I'm a little confused.

The problem is with URI.parse [1] ― it doesn't like spaces before or in between get params.

1.9.3p0 :002 > URI.parse "http://localhost/?gems= sinatra,foobar"
URI::InvalidURIError: bad URI(is not URI?): http://localhost/?gems= sinatra,foobar

There are two ways to fix this.

  • Strip trailing + leading whitespace before calling URI.parse
  • URI.encode(gem_names.join(","))

Both will fix the error and will give an error like following:

Gemfile
======
source :rubygems
gem 'sinatra'
gem ' rspec', '~> 2.5.0'

Error
====
Could not find gem ' rspec (~> 2.5.0) ruby' in the gems available on this machine.

I don't think encoding is such a good idea because I think the rubygems api doesn't return a good result:

९ curl -v http://rubygems.org/api/v1/dependencies?gems=%20sinatra
* About to connect() to rubygems.org port 80 (#0)
*   Trying 72.4.120.124... connected
* Connected to rubygems.org (72.4.120.124) port 80 (#0)
> GET /api/v1/dependencies?gems=%20sinatra HTTP/1.1
> User-Agent: curl/7.21.6 (x86_64-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
> Host: rubygems.org
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 09 Mar 2012 06:03:37 GMT
< Server: Apache/2.2.3 (Red Hat) mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5 Phusion_Passenger/3.0.11
< X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
< ETag: "c21d9ae195b0d525cd96fab205882683"
< Cache-Control: max-age=0, private, must-revalidate
< X-UA-Compatible: IE=Edge,chrome=1
< X-Runtime: 0.002853
< Status: 200
< Vary: Accept-Encoding
< Content-Length: 4
< Content-Type: text/html; charset=utf-8
< 
* Connection #0 to host rubygems.org left intact
* Closing connection #0

To really fix the problem I guess we should clean up the gem names much before like when parsing/reading the Gemfile?

EDIT
[1] https://github.com/carlhuda/bundler/blob/master/lib/bundler/fetcher.rb#L161 ― this is the line that raises the error.

Contributor

rohit commented Mar 10, 2012

Ok I guess this can be silently fixed in Bundler::Dsl inside _normalize_options() or in gem() by cleaning trailing and leading whitespace. Desirable?

Owner

indirect commented Mar 10, 2012

@rohit, I don't think it's a good idea to silently manipulate the user's explicit input.

We should fix the new exception in Bundler 1.1 by correctly URL-escaping each gem name before we use the names to build the URL for the query. Once that is done, 1.1 should return the same "gem not found" error that 1.0 does. Thanks!

Contributor

rohit commented Mar 11, 2012

This was solved in 1-1-stable branch in d49f78b

@indirect or @korny can one of you close this issue? :)

korny commented Mar 11, 2012

Issue fixed, thank you!

@korny korny closed this Mar 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment