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

Patch load error in case GemSpecError #34557

Merged
merged 1 commit into from Nov 28, 2018

Conversation

sergioisidoro
Copy link
Contributor

@sergioisidoro sergioisidoro commented Nov 28, 2018

Summary

I stumbled upon this error while trying to make a basic.

2.3.4 :008 > ActiveRecord::Base.establish_connection(                                                                                          
2.3.4 :009 >       "adapter"  => "sqlite3",                                                                                                    
2.3.4 :010 >       "database" => "path/to/dbfile"                                                                                              
2.3.4 :011?>     )       

And it gave out a:

ArgumentError: wrong number of arguments (given 1, expected 2)                                                                                                                                  
        from /Users/sergio/.rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/rubygems/errors.rb:28:in `initialize'                                                                                
        from /Users/sergio/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.1.1/lib/active_record/connection_adapters/connection_specification.rb:203:in `exception'                                  
        from /Users/sergio/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.1.1/lib/active_record/connection_adapters/connection_specification.rb:203:in `raise'                                      
        from /Users/sergio/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.1.1/lib/active_record/connection_adapters/connection_specification.rb:203:in `rescue in spec'                             
        from /Users/sergio/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.1.1/lib/active_record/connection_adapters/connection_specification.rb:190:in `spec'                                       
        from /Users/sergio/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:950:in `establish_connection'                       
        from /Users/sergio/.rvm/gems/ruby-2.3.4/gems/activerecord-5.2.1.1/lib/active_record/connection_handling.rb:60:in `establish_connection'                                                 
        from (irb):21                                                                                                                                                                           
        from /Users/sergio/.rvm/rubies/ruby-2.3.4/bin/irb:11:in `<main>'                                                                                  

It seems that I was missing a dependency (sqlite3 sigh) , and Gem MissingSpecError has some problems here in initialisation -- it requires 2 arguments .

I replicated the offending line:

(byebug) raise e.class, "Hello", e.backtrace
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2)

nil

It seems like LoadError also catches MissingSpecError. The last one requires 2 arguments, and fails to provide a meaningful error message. -- http://ruby-doc.org/stdlib-2.4.0_preview1/libdoc/rubygems/rdoc/Gem/MissingSpecError.html

In this PR we would be casting that error to a LoadError instead when rescuing and re-raising a MissingSpecError (since we would need more complex arguments)

The alternative would be to create some convoluted logic for handling these 2 types of exceptions

@rafaelfranca rafaelfranca merged commit 9c6e362 into rails:master Nov 28, 2018
rafaelfranca added a commit that referenced this pull request Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants