Skip to content

Commit d33e3eb

Browse files
hsbtclaude
andcommitted
Fire after-fetch and after-git-fetch hooks even on failure
Wrap the fetch/checkout operations in begin/ensure so the after hook fires even when the underlying fetch raises. This matches the existing GEM_AFTER_INSTALL hook, which fires on both success and failure paths (via internal error-to-state conversion in ParallelInstaller#do_install). Without this, plugins relying on before/after pairs for cleanup or timing would see unbalanced hook invocations whenever a network or checkout error occurs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent acc0659 commit d33e3eb

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

bundler/lib/bundler/source/git.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,12 @@ def specs(*)
192192

193193
if requires_checkout? && !@copied
194194
Plugin.hook(Plugin::Events::GIT_BEFORE_FETCH, self)
195-
fetch unless use_app_cache?
196-
checkout
197-
Plugin.hook(Plugin::Events::GIT_AFTER_FETCH, self)
195+
begin
196+
fetch unless use_app_cache?
197+
checkout
198+
ensure
199+
Plugin.hook(Plugin::Events::GIT_AFTER_FETCH, self)
200+
end
198201
end
199202

200203
local_specs

bundler/lib/bundler/source/rubygems.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,13 @@ def download_gem(spec, download_cache_path, previous_spec = nil)
478478
gem_remote_fetcher = remote_fetchers.fetch(spec.remote).gem_remote_fetcher
479479

480480
Plugin.hook(Plugin::Events::GEM_BEFORE_FETCH, spec)
481-
Gem.time("Downloaded #{spec.name} in", 0, true) do
482-
Bundler.rubygems.download_gem(spec, uri, download_cache_path, gem_remote_fetcher)
481+
begin
482+
Gem.time("Downloaded #{spec.name} in", 0, true) do
483+
Bundler.rubygems.download_gem(spec, uri, download_cache_path, gem_remote_fetcher)
484+
end
485+
ensure
486+
Plugin.hook(Plugin::Events::GEM_AFTER_FETCH, spec)
483487
end
484-
Plugin.hook(Plugin::Events::GEM_AFTER_FETCH, spec)
485488
end
486489

487490
# Returns the global cache path of the calling Rubygems::Source object.

0 commit comments

Comments
 (0)