diff options
author | The Bundler Bot <bot@bundler.io> | 2018-03-17 21:24:30 +0000 |
---|---|---|
committer | Colby Swandale <me@colby.fyi> | 2018-10-05 13:30:55 +1000 |
commit | 507d629061835f6d3aabe0954dc7f12755202d3f (patch) | |
tree | 091d32128942c82f0c678888a624606fefd4c003 | |
parent | 055715dc6eb4bc16c8e70d01a73c22f015cd804f (diff) | |
download | bundler-507d629061835f6d3aabe0954dc7f12755202d3f.tar.gz |
Auto merge of #6310 - utilum:rescue_unspecified_exception, r=segiddins
Fix some rescue calls that do not specifiy error type.
The problem I noticed was in style, several instances of `rescue` clauses that do not specify an exception type. This is noted in in the Ruby Style Guide as [Avoid rescuing the Exception class](https://github.com/bbatsov/ruby-style-guide#no-blind-rescues).
My diagnosis was that at least some of those are leftover style. They are noted in `.rubocop_todo.yml`. To make sure, I asked on Slack.
My fix is to make as many of them more specific, specifying at least `StandardError`, and trying to be more specific.
No other ways of addressing this came to mind. I'd be happy to consider.
(cherry picked from commit ff6b8712a0337305ba9617e35545b9e8f8cd4a53)
-rw-r--r-- | lib/bundler.rb | 4 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/endpoint_specification.rb | 2 | ||||
-rw-r--r-- | lib/bundler/env.rb | 2 | ||||
-rw-r--r-- | lib/bundler/fetcher.rb | 2 | ||||
-rw-r--r-- | lib/bundler/gem_helper.rb | 2 | ||||
-rw-r--r-- | lib/bundler/installer/gem_installer.rb | 2 | ||||
-rw-r--r-- | lib/bundler/installer/parallel_installer.rb | 2 | ||||
-rw-r--r-- | lib/bundler/mirror.rb | 4 | ||||
-rw-r--r-- | lib/bundler/plugin.rb | 4 | ||||
-rw-r--r-- | lib/bundler/plugin/index.rb | 2 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 2 | ||||
-rw-r--r-- | task/release.rake | 2 |
13 files changed, 16 insertions, 16 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 52bbc57fb5..829dc5d949 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -191,7 +191,7 @@ module Bundler end tmp_home_path.join(login).tap(&:mkpath) end - rescue => e + rescue RuntimeError => e raise e.exception("#{warning}\nBundler also failed to create a temporary home directory at `#{path}':\n#{e}") end @@ -416,7 +416,7 @@ EOF def load_marshal(data) Marshal.load(data) - rescue => e + rescue StandardError => e raise MarshalError, "#{e.class}: #{e.message}" end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 7dd54671de..ec757b625e 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -741,7 +741,7 @@ module Bundler end Bundler.ui.warn "The latest bundler is #{latest}, but you are currently running #{current}.\n#{suggestion}" - rescue + rescue RuntimeError nil end end diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb index 8668c4ea7f..9a00b64e0e 100644 --- a/lib/bundler/endpoint_specification.rb +++ b/lib/bundler/endpoint_specification.rb @@ -123,7 +123,7 @@ module Bundler @required_ruby_version = Gem::Requirement.new(v) end end - rescue => e + rescue StandardError => e raise GemspecError, "There was an error parsing the metadata for the gem #{name} (#{version}): #{e.class}\n#{e}\nThe metadata was #{data.inspect}" end diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 6e13b8f9f4..171b6520ad 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -64,7 +64,7 @@ module Bundler Bundler.read_file(filename.to_s).strip rescue Errno::ENOENT "<No #{filename} found>" - rescue => e + rescue RuntimeError => e "#{e.class}: #{e.message}" end diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 444778b36b..4dd42e42ff 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -178,7 +178,7 @@ module Bundler # engine_version raises on unknown engines engine_version = begin ruby.engine_versions - rescue + rescue RuntimeError "???" end agent << " #{ruby.engine}/#{ruby.versions_string(engine_version)}" diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 1d7fc508d5..e7673cba88 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -153,7 +153,7 @@ module Bundler sh "git tag -m \"Version #{version}\" #{version_tag}" Bundler.ui.confirm "Tagged #{version_tag}." yield if block_given? - rescue + rescue RuntimeError Bundler.ui.error "Untagging #{version_tag} due to error." sh_with_code "git tag -d #{version_tag}" raise diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb index d4ef4942e2..e5e245f970 100644 --- a/lib/bundler/installer/gem_installer.rb +++ b/lib/bundler/installer/gem_installer.rb @@ -21,7 +21,7 @@ module Bundler raise rescue Errno::ENOSPC return false, out_of_space_message - rescue => e + rescue StandardError => e return false, specific_failure_message(e) end diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 95d9575c44..235882f71f 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -160,7 +160,7 @@ module Bundler ) success, message = begin gem_installer.install_from_spec - rescue => e + rescue RuntimeError => e raise e, "#{e}\n\n#{require_tree_for_spec(spec_install.spec)}" end if success diff --git a/lib/bundler/mirror.rb b/lib/bundler/mirror.rb index a6fa070eb8..b15190e7e5 100644 --- a/lib/bundler/mirror.rb +++ b/lib/bundler/mirror.rb @@ -152,7 +152,7 @@ module Bundler socket.connect_nonblock(address) rescue Errno::EINPROGRESS wait_for_writtable_socket(socket, address, timeout) - rescue # Connection failed somehow, again + rescue RuntimeError # Connection failed somehow, again false end end @@ -172,7 +172,7 @@ module Bundler socket.connect_nonblock(address) rescue Errno::EISCONN true - rescue # Connection failed + rescue StandardError # Connection failed false end end diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index 99c9a867b0..3f23fee2e0 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -66,7 +66,7 @@ module Bundler installed_specs = Installer.new.install_definition(definition) save_plugins plugins, installed_specs, builder.inferred_plugins - rescue => e + rescue RuntimeError => e unless e.is_a?(GemfileError) Bundler.ui.error "Failed to install plugin: #{e.message}\n #{e.backtrace[0]}" end @@ -264,7 +264,7 @@ module Bundler load path.join(PLUGIN_FILE_NAME) @loaded_plugin_names << name - rescue => e + rescue RuntimeError => e Bundler.ui.error "Failed loading plugin #{name}: #{e.message}" raise end diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 770a98de3a..f09587dfda 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -63,7 +63,7 @@ module Bundler @plugin_paths[name] = path @load_paths[name] = load_paths save_index - rescue + rescue StandardError @commands = old_commands raise end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 5b295b525e..69e955fcb4 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -79,7 +79,7 @@ module Bundler required_file = file begin Kernel.require file - rescue => e + rescue RuntimeError => e raise e if e.is_a?(LoadError) # we handle this a little later raise Bundler::GemRequireError.new e, "There was an error while trying to load the gem '#{file}'." diff --git a/task/release.rake b/task/release.rake index 42c120fecd..f1786e8bc2 100644 --- a/task/release.rake +++ b/task/release.rake @@ -38,7 +38,7 @@ namespace :release do if response.code.to_i >= 400 raise "#{uri}\n#{response.inspect}\n#{begin JSON.parse(response.body) - rescue + rescue JSON::ParseError response.body end}" end |