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

ActiveRecord errors while handling error without Bundler #32830

Closed
JoshCheek opened this issue May 6, 2018 · 5 comments
Closed

ActiveRecord errors while handling error without Bundler #32830

JoshCheek opened this issue May 6, 2018 · 5 comments

Comments

@JoshCheek
Copy link
Contributor

Synopsis

When running ActiveRecord, it tries to require the adapter. When requiring the adapter fails, it catches the error message and tries to reraise it with a helpful error explaining that you need to install the gem. When Bundler is loaded, it calls the methods that Bundler monkey patches, which raises a Gem::LoadError, and everything works. However, without Bundler, the non-monkey patched version is called, which raises a Gem::MissingSpecError. These aren't compatible because they are initialized differently:

Gem::LoadError.instance_method(:initialize).parameters
# => [[:rest]]

Gem::MissingSpecError.instance_method(:initialize).parameters
# => [[:req, :name], [:req, :requirement]]

So, when ActiveRecord tries to reraise it (here), it explodes.

I've also reported this to Bundler here. There's a bit more analysis there, I'd reproduce it here, but my cat is interfering with my typing.

Steps to reproduce

Invoke bash run.sh from this gist.

Expected behavior

An error with the message "Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile."

Actual behavior

An error with the message "wrong number of arguments (given 1, expected 2)"

System configuration

ActiveRecord version: 5.2.0
Ruby version: 2.5.0
Rubygems version: 2.7.6
Rubygems version: 1.16.1

y-yagi added a commit to y-yagi/rails that referenced this issue May 9, 2018
If not using Bundler and the specified adapter gem does not exist,
`rubygems` raises `Gem::MissingSpecError`.

`Gem::MissingSpecError` inherits `LoadError`, but the argument of `initialize`
is different.
https://github.com/rubygems/rubygems/blob/9054079ce8a1ad05dd206a3562339b74712c7fc6/lib/rubygems/errors.rb#L27..L31

As a result, `ArugmentError` occurs when re-raising the exception.

Although it is possible to check the error class and specify appropriate
arguments for each of them, I think that it is sufficient to just raise
`LoadError`.

Together, when using Bundler, fixed that gem which error occurred could
not be checked correctly.

Fixes rails#32830.
@rails-bot rails-bot bot added the stale label Aug 4, 2018
@rails-bot
Copy link

rails-bot bot commented Aug 4, 2018

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-2-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.

@rails-bot rails-bot bot closed this as completed Aug 11, 2018
@JoshCheek
Copy link
Contributor Author

@rails-bot rails-bot bot removed the stale label Sep 2, 2018
@JoshCheek
Copy link
Contributor Author

I don't seem to have a reopen button.

@JoshCheek
Copy link
Contributor Author

❤️s for @rafaelfranca!!

@y-yagi
Copy link
Member

y-yagi commented Nov 29, 2018

Fixed by #34557.

@y-yagi y-yagi closed this as completed Nov 29, 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 a pull request may close this issue.

3 participants