rails / spring

Rails application preloader
MIT License
2.81k stars 341 forks source link

Run without error if spring is in uninstalled group #684

Open mkllnk opened 2 years ago

mkllnk commented 2 years ago

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: https://github.com/rails/spring/compare/main...mkllnk:handle-missing-gem