diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2021-08-19 11:57:16 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-08-31 19:06:14 +0900 |
commit | f934096638ec5850b65e45dc7230900107441288 (patch) | |
tree | e91661feb40a38070e0f4296229fa37db22e0aa9 /lib/bundler/plugin.rb | |
parent | 3a9dd795a70705d130fb856db148b068d26821c1 (diff) |
[rubygems/rubygems] Make plugin installation idempotent
The error had not be caught be specs because `bundle install` was
returning a zero exit code when plugin installation errors happened. So
I fixed that issue too.
https://github.com/rubygems/rubygems/commit/90cde87856
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4789
Diffstat (limited to 'lib/bundler/plugin.rb')
-rw-r--r-- | lib/bundler/plugin.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index ab4b209f6e..158c69e1a1 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -13,6 +13,7 @@ module Bundler class MalformattedPlugin < PluginError; end class UndefinedCommandError < PluginError; end class UnknownSourceError < PluginError; end + class PluginInstallError < PluginError; end PLUGIN_FILE_NAME = "plugins.rb".freeze @@ -38,12 +39,11 @@ module Bundler specs = Installer.new.install(names, options) save_plugins names, specs - rescue PluginError => e + rescue PluginError 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) } - 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 ")}" + raise end # Uninstalls plugins by the given names @@ -245,6 +245,8 @@ module Bundler # @param [Array<String>] names of inferred source plugins that can be ignored def save_plugins(plugins, specs, optional_plugins = []) plugins.each do |name| + next if index.installed?(name) + spec = specs[name] save_plugin(name, spec, optional_plugins.include?(name)) @@ -269,11 +271,13 @@ module Bundler # @param [Boolean] optional_plugin, removed if there is conflict with any # other plugin (used for default source plugins) # - # @raise [MalformattedPlugin] if validation or registration raises any error + # @raise [PluginInstallError] if validation or registration raises any error def save_plugin(name, spec, optional_plugin = false) validate_plugin! Pathname.new(spec.full_gem_path) installed = register_plugin(name, spec, optional_plugin) Bundler.ui.info "Installed plugin #{name}" if installed + rescue PluginError => e + raise PluginInstallError, "Failed to install plugin `#{spec.name}`, due to #{e.class} (#{e.message})" end # Runs the plugins.rb file in an isolated namespace, records the plugin |