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

Fix error when Bundler installation is corrupted #7642

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bundler/lib/bundler/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,18 @@ def message

status_code(38)
end

class CorruptBundlerInstallError < BundlerError
def initialize(loaded_spec)
@loaded_spec = loaded_spec
end

def message
"The running version of Bundler (#{Bundler::VERSION}) does not match the version of the specification installed for it (#{@loaded_spec.version}). " \
"This can be caused by reinstalling Ruby without removing previous installation, leaving around an upgraded default version of Bundler. " \
"Reinstalling Ruby from scratch should fix the problem."
end

status_code(39)
end
end
2 changes: 2 additions & 0 deletions bundler/lib/bundler/source/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def specs
end

if local_spec = Gem.loaded_specs["bundler"]
raise CorruptBundlerInstallError.new(local_spec) if local_spec.version.to_s != Bundler::VERSION

idx << local_spec
else
idx << Gem::Specification.new do |s|
Expand Down
29 changes: 29 additions & 0 deletions bundler/spec/commands/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1407,4 +1407,33 @@ def run
expect(bundled_app(".bundle/config")).not_to exist
end
end

context "when bundler installation is corrupt" do
before do
system_gems "bundler-9.99.8"

replace_version_file("9.99.9", dir: system_gem_path("gems/bundler-9.99.8"))
end

it "shows a proper error" do
lockfile <<~L
GEM
remote: #{file_uri_for(gem_repo1)}/
specs:

PLATFORMS
#{lockfile_platforms}

DEPENDENCIES

BUNDLED WITH
9.99.8
L

install_gemfile "source \"#{file_uri_for(gem_repo1)}\"", env: { "BUNDLER_VERSION" => "9.99.8" }, raise_on_error: false

expect(err).not_to include("ERROR REPORT TEMPLATE")
expect(err).to include("The running version of Bundler (9.99.9) does not match the version of the specification installed for it (9.99.8)")
end
end
end