From 310937a546f448603c995fe2bdff0fa7e0610427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 23 Jul 2021 21:32:07 +0200 Subject: [PATCH] Move rescue block around the code that can raise it --- bundler/lib/bundler/cli/install.rb | 8 +------- bundler/lib/bundler/runtime.rb | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bundler/lib/bundler/cli/install.rb b/bundler/lib/bundler/cli/install.rb index 42b9a3f47c03..4c1915fea6e6 100644 --- a/bundler/lib/bundler/cli/install.rb +++ b/bundler/lib/bundler/cli/install.rb @@ -60,7 +60,7 @@ def run installer = Installer.install(Bundler.root, definition, options) Bundler.settings.temporary(:cache_all_platforms => options[:local] ? false : Bundler.settings[:cache_all_platforms]) do - Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? + Bundler.load.cache(nil, options[:local]) if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? end Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}." @@ -83,12 +83,6 @@ def run end Bundler::CLI::Common.output_fund_metadata_summary - rescue GemNotFound - if options[:local] - Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory." - end - - raise rescue Gem::InvalidSpecificationException Bundler.ui.warn "You have one or more invalid gemspecs that need to be fixed." raise diff --git a/bundler/lib/bundler/runtime.rb b/bundler/lib/bundler/runtime.rb index 287fa1cfe94b..32a94a7e67d4 100644 --- a/bundler/lib/bundler/runtime.rb +++ b/bundler/lib/bundler/runtime.rb @@ -104,7 +104,7 @@ def lock(opts = {}) alias_method :gems, :specs - def cache(custom_path = nil) + def cache(custom_path = nil, local = false) cache_path = Bundler.app_cache(custom_path) SharedHelpers.filesystem_access(cache_path) do |p| FileUtils.mkdir_p(p) @@ -112,7 +112,20 @@ def cache(custom_path = nil) Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}" - specs_to_cache = Bundler.settings[:cache_all_platforms] ? @definition.resolve.materialized_for_all_platforms : specs + specs_to_cache = if Bundler.settings[:cache_all_platforms] + @definition.resolve.materialized_for_all_platforms + else + begin + specs + rescue GemNotFound + if local + Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory." + end + + raise + end + end + specs_to_cache.each do |spec| next if spec.name == "bundler" next if spec.source.is_a?(Source::Gemspec)