From 26bf079fd3109e86cbcce31d6abde9498664e8a9 Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Mon, 2 Dec 2024 15:38:53 -0700 Subject: [PATCH] inform user about bundler problem --- CHANGELOG | 1 + .../phusion_passenger/loader_shared_helpers.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 6016cf0450..e86e896f3c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Release 6.0.25 (Not yet released) ------------- * [Standalone] Changes Passenger (not app) start and stop timeouts to 25s (from 15s) except for Nginx engine mode, which retains a stop timeout of 60s. + * [Ruby] Cause bundler version mismatch to output an intelligible error message. Closes GH-2567 and gh-2577. * diff --git a/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb b/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb index 3281441c93..4e28678bad 100644 --- a/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb +++ b/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb @@ -210,6 +210,17 @@ def run_load_path_setup_code(options) # # The existence of Gemfile/gems.rb indicates whether (2) is true: elsif File.exist?('Gemfile') || File.exist?('gems.rb') + # Bundler 2.5.12+ throws a hissy fit if you don't have the + # version of bundler installed with which the Gemfile.lock was + # created. This causes extremely inscrutible error messages such + # as `/usr/bin/ruby doesn't exist`, so we cause RubyGems to raise + # an intelligible error here instead. + if File.exist?('Gemfile.lock') + lockfile_contents = File.read('Gemfile.lock').lines.map(&:strip) + index = lockfile_contents.index 'BUNDLED WITH' + bundler_version = lockfile_contents[index + 1] unless index.nil? + found = Gem::Specification.find_by_name('bundler', "= #{bundler_version}") unless bundler_version.nil? + end # In case of Rails 3+, config/boot.rb already calls Bundler.setup. # However older versions of Rails may not so loading boot.rb might # not be the correct thing to do. To be on the safe side we