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

Run without error if spring is in uninstalled group #684

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkllnk
Copy link

@mkllnk mkllnk commented Oct 5, 2022

We couldn't run the console on our production server since updating our binstubs with #662. Our setup has not been considered in that change but we found an easy change to the spring binstub which I'm sharing here.

We have spring in the development and test groups which means that it's present in the Gemfile but not installed on production. We are also not using the RAILS_ENV variable when logging in as developer and start a console with a parameter:

./bin/rails console -e production

In this case, a Gem::LoadError was raised when trying to load spring. So since checking the RAILS_ENV is not a reliable detection of spring being installed, we added a rescue call.

But looking into this issue further, I discovered that we can go through the list of actually requested gems and skip spring if it wasn't requested. This solves our specific case. A rescue statement may still be useful if other people have other reasons for the gem not being installed but I don't know if that's possible. An alternative or additional patch is available if you are interested but it may not be necessary: main...mkllnk:handle-missing-gem

We have spring in the development and test groups which means that it's
present in the Gemfile but not installed on production. We are also not
using the RAILS_ENV variable when logging in as developer and start a
console with a parameter:

    ./bin/rails console -e production

In this case, a LoadError was raised when trying to load spring. So
since checking the RAILS_ENV is not a reliable detection of spring being
installed, we added a rescue call.

But looking into this issue further, I discovered that we can go through
the list of actually requested gems and skip spring if it wasn't
requested. This solves our specific case. A rescue statement may still
be useful if other people have other reasons for the gem not being
installed but I don't know if that's possible.
FileUtils.mv(gem_home.join(name), app.root)
FileUtils.mv(spec_home.join("#{name}.gemspec"), app.root)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without moving the spec file, gem "spring", spring.version succeeds even though the gem code isn't there. The the next line raises a LoadError instead of a Gem::LoadError. That doesn't really matter for this solution but was an issue when trying to rescue only the Gem::LoadError. Anyway, I thought that this is more realistic for future specs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant