Fix crash caused by RubyGems require
gem activation logic running before Bundler can properly register its own monkeypatches
#7647
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.
What was the end-user or developer problem that led to this PR?
In #7603, we added a monkeypatch to
Gem::StubSpecification#data
so that when we fail to read the underlying gemspec due to not being readable, we can print a friendly error message. In order to do that, we reused a Bundler helper that knows how to rescue filesystem errors and re-raise them in way that Bundler knows how to handle in a friendly way.This usage of
Bundler::SharedHelpers
was added without an explicitrequire
because Bundler is supposed to setup anautoload
forBundler::SharedHelpers
. However, theautoload
does not seem to be triggering under some situations, such as when loading our own Rakefile. But that also does not happen always, but only when you have two different versions ofpsych
installed in your system.This is why:
rdoc/task
which activatesrdoc
, which depends onpsych >= 4.0
.psych
versions in the system, RubyGemsrequire
does not automatically activatepsych
but adds it toGem::Specification.unresolved_deps
and then furtherrequire
calls will check in the potential paths for thoseunresolved_deps
to see if any unresolved dependency can be activated. This enables logic that ends up usingGem::StubSpecification#data
.bundler/gem_tasks
is required that eventually requiresbundler/rubygems_ext
and enables the monkeypatch toGem::StubSpecification#data
.bundler/gem_tasks
eventually loadsbundler.rb
and sets up an autoload forBundler::SharedHelpers
, otherrequire
calls are run that eventually useGem::Specification#data
for gem activation withoutBundler::SharedHelpers
being available yet.What is your fix for the problem, implemented in this PR?
The fix to
require "bundler/shared_helpers"
before using it. However, that's not enough because thatrequire
itself ends up running into the same error. So on top of that, I made sure no standardrequire
calls are used during loading ofbundler/shared_helpers
.Closes #7638.