Skip to content

Commit

Permalink
Merge pull request #3487 from fatkodima/fix-plugin-install-rescue
Browse files Browse the repository at this point in the history
Fix broken exception recovery code when installing plugins

(cherry picked from commit b277c8c)
  • Loading branch information
deivid-rodriguez committed Oct 6, 2020
1 parent 9b616b4 commit 0e316e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions bundler/lib/bundler/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ def install(names, options)

save_plugins names, specs
rescue PluginError => e
if specs
specs_to_delete = Hash[specs.select {|k, _v| names.include?(k) && !index.commands.values.include?(k) }]
specs_to_delete.values.each {|spec| Bundler.rm_rf(spec.full_gem_path) }
end
specs_to_delete = specs.select {|k, _v| names.include?(k) && !index.commands.values.include?(k) }
specs_to_delete.each_value {|spec| Bundler.rm_rf(spec.full_gem_path) }

Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}"
names_list = names.map {|name| "`#{name}`" }.join(", ")
Bundler.ui.error "Failed to install the following plugins: #{names_list}. The underlying error was: #{e.message}.\n #{e.backtrace.join("\n ")}"
end

# Uninstalls plugins by the given names
Expand Down
2 changes: 1 addition & 1 deletion bundler/spec/plugins/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def exec(command, args)

expect(out).not_to include("Installed plugin copycat")

expect(err).to include("Failed to install plugin")
expect(err).to include("Failed to install the following plugins: `copycat`")

expect(err).to include("Command(s) `mahcommand` declared by copycat are already registered.")
end
Expand Down
2 changes: 1 addition & 1 deletion bundler/spec/plugins/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def exec(command, args)

bundle "plugin install charlie --source #{file_uri_for(gem_repo2)}"

expect(err).to include("plugins.rb was not found")
expect(err).to include("Failed to install the following plugins: `charlie`. The underlying error was: plugins.rb was not found")

expect(global_plugin_gem("charlie-1.0")).not_to be_directory

Expand Down

0 comments on commit 0e316e4

Please sign in to comment.