Run without error if spring is in uninstalled group#684
Open
mkllnk wants to merge 1 commit intorails:mainfrom
Open
Run without error if spring is in uninstalled group#684mkllnk wants to merge 1 commit intorails:mainfrom
mkllnk wants to merge 1 commit intorails:mainfrom
Conversation
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.
mkllnk
commented
Oct 5, 2022
| gem_home = app.gem_home.join('gems') | ||
| spec_home = app.gem_home.join('specifications') | ||
| FileUtils.mv(gem_home.join(name), app.root) | ||
| FileUtils.mv(spec_home.join("#{name}.gemspec"), app.root) |
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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