[rubygems/rubygems] util/rubocop -A --only Style/RescueStandardError

https://github.com/rubygems/rubygems/commit/80b57da926
This commit is contained in:
Hiroshi SHIBATA 2023-03-16 13:47:12 +09:00
parent 70164eec0f
commit 6ad269dc39
23 changed files with 33 additions and 33 deletions

View File

@ -432,7 +432,7 @@ class Gem::Command
begin begin
parser.parse!(args.dup) parser.parse!(args.dup)
return true return true
rescue rescue StandardError
return false return false
end end
end end

View File

@ -42,7 +42,7 @@ class Gem::Commands::CheckCommand < Gem::Command
say say
gems = begin gems = begin
get_all_gem_names get_all_gem_names
rescue rescue StandardError
[] []
end end

View File

@ -98,7 +98,7 @@ permission to.
action = method == :delete ? "Removing" : "Adding" action = method == :delete ? "Removing" : "Adding"
with_response response, "#{action} #{owner}" with_response response, "#{action} #{owner}"
rescue rescue StandardError
# ignore # ignore
end end
end end

View File

@ -108,7 +108,7 @@ Specific fields in the specification can be extracted in YAML format:
if File.exist? gem if File.exist? gem
begin begin
specs << Gem::Package.new(gem).spec specs << Gem::Package.new(gem).spec
rescue rescue StandardError
nil nil
end end
end end

View File

@ -88,7 +88,7 @@ data you will need to change them immediately and yank your gem.
def get_version_from_requirements(requirements) def get_version_from_requirements(requirements)
requirements.requirements.first[1].version requirements.requirements.first[1].version
rescue rescue StandardError
nil nil
end end

View File

@ -79,7 +79,7 @@ module Gem
def self.find_home def self.find_home
Dir.home.dup Dir.home.dup
rescue rescue StandardError
if Gem.win_platform? if Gem.win_platform?
File.expand_path File.join(ENV["HOMEDRIVE"] || ENV["SystemDrive"], "/") File.expand_path File.join(ENV["HOMEDRIVE"] || ENV["SystemDrive"], "/")
else else
@ -185,7 +185,7 @@ module Gem
def self.default_exec_format def self.default_exec_format
exec_format = begin exec_format = begin
RbConfig::CONFIG["ruby_install_name"].sub("ruby", "%s") RbConfig::CONFIG["ruby_install_name"].sub("ruby", "%s")
rescue rescue StandardError
"%s" "%s"
end end

View File

@ -74,7 +74,7 @@ class Gem::Ext::Builder
build_env = { "SOURCE_DATE_EPOCH" => Gem.source_date_epoch_string }.merge(env) build_env = { "SOURCE_DATE_EPOCH" => Gem.source_date_epoch_string }.merge(env)
output, status = begin output, status = begin
Open3.capture2e(build_env, *command, :chdir => dir) Open3.capture2e(build_env, *command, :chdir => dir)
rescue => error rescue StandardError => error
raise Gem::InstallError, "#{command_name || class_name} failed#{error.message}" raise Gem::InstallError, "#{command_name || class_name} failed#{error.message}"
end end
if verbose if verbose
@ -174,7 +174,7 @@ EOF
verbose { results.join("\n") } verbose { results.join("\n") }
write_gem_make_out results.join "\n" write_gem_make_out results.join "\n"
rescue => e rescue StandardError => e
results << e.message results << e.message
build_error(results.join("\n"), $@) build_error(results.join("\n"), $@)
end end

View File

@ -199,7 +199,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
output, status = output, status =
begin begin
Open3.capture2e(cargo, "metadata", "--no-deps", "--format-version", "1", :chdir => cargo_dir) Open3.capture2e(cargo, "metadata", "--no-deps", "--format-version", "1", :chdir => cargo_dir)
rescue => error rescue StandardError => error
raise Gem::InstallError, "cargo metadata failed #{error.message}" raise Gem::InstallError, "cargo metadata failed #{error.message}"
end end

View File

@ -34,7 +34,7 @@ class Gem::GemRunner
begin begin
Gem.load_env_plugins Gem.load_env_plugins
rescue rescue StandardError
nil nil
end end
Gem.load_plugins Gem.load_plugins

View File

@ -669,7 +669,7 @@ EOM
when "data.tar.gz" then when "data.tar.gz" then
verify_gz entry verify_gz entry
end end
rescue rescue StandardError
warn "Exception while verifying #{@gem.path}" warn "Exception while verifying #{@gem.path}"
raise raise
end end

View File

@ -126,7 +126,7 @@ class Gem::RemoteFetcher
require "fileutils" require "fileutils"
begin begin
FileUtils.mkdir_p cache_dir FileUtils.mkdir_p cache_dir
rescue rescue StandardError
nil nil
end unless File.exist? cache_dir end unless File.exist? cache_dir
@ -286,7 +286,7 @@ class Gem::RemoteFetcher
def cache_update_path(uri, path = nil, update = true) def cache_update_path(uri, path = nil, update = true)
mtime = begin mtime = begin
path && File.stat(path).mtime path && File.stat(path).mtime
rescue rescue StandardError
nil nil
end end

View File

@ -176,14 +176,14 @@ class Gem::Security::Signer
disk_cert_path = File.join(Gem.default_cert_path) disk_cert_path = File.join(Gem.default_cert_path)
disk_cert = begin disk_cert = begin
File.read(disk_cert_path) File.read(disk_cert_path)
rescue rescue StandardError
nil nil
end end
disk_key_path = File.join(Gem.default_key_path) disk_key_path = File.join(Gem.default_key_path)
disk_key = begin disk_key = begin
OpenSSL::PKey.read(File.read(disk_key_path), @passphrase) OpenSSL::PKey.read(File.read(disk_key_path), @passphrase)
rescue rescue StandardError
nil nil
end end

View File

@ -137,7 +137,7 @@ class Gem::Source
spec = Gem.read_binary local_spec spec = Gem.read_binary local_spec
spec = begin spec = begin
Marshal.load(spec) Marshal.load(spec)
rescue rescue StandardError
nil nil
end end
return spec if spec return spec if spec

View File

@ -1520,7 +1520,7 @@ class Gem::Specification < Gem::BasicSpecification
else else
executables executables
end end
rescue rescue StandardError
return nil return nil
end end

View File

@ -59,7 +59,7 @@ Run `gem update --system #{Gem.latest_rubygems_version}` to update your installa
return eglible return eglible
end end
rescue # don't block install command on any problem rescue StandardError # don't block install command on any problem
false false
end end

View File

@ -85,7 +85,7 @@ module Gem::Util
loop do loop do
begin begin
Dir.chdir here, &block Dir.chdir here, &block
rescue rescue StandardError
Errno::EACCES Errno::EACCES
end end

View File

@ -345,7 +345,7 @@ class Gem::TestCase < Test::Unit::TestCase
$LOAD_PATH.map! do |s| $LOAD_PATH.map! do |s|
expand_path = begin expand_path = begin
File.realpath(s) File.realpath(s)
rescue rescue StandardError
File.expand_path(s) File.expand_path(s)
end end
if expand_path != s if expand_path != s
@ -1527,7 +1527,7 @@ Also, a list:
def self.cert_path(cert_name) def self.cert_path(cert_name)
if begin if begin
Time.at(2**32) Time.at(2**32)
rescue rescue StandardError
32 32
end == 32 end == 32
cert_file = "#{__dir__}/#{cert_name}_cert_32.pem" cert_file = "#{__dir__}/#{cert_name}_cert_32.pem"

View File

@ -664,7 +664,7 @@ class TestGem < Gem::TestCase
gemdir = File.join @tempdir, "a/b/c/gemdir" gemdir = File.join @tempdir, "a/b/c/gemdir"
begin begin
FileUtils.rm_rf File.join(@tempdir, "a") FileUtils.rm_rf File.join(@tempdir, "a")
rescue rescue StandardError
nil nil
end end
refute File.exist?(File.join(@tempdir, "a")), refute File.exist?(File.join(@tempdir, "a")),
@ -681,7 +681,7 @@ class TestGem < Gem::TestCase
gemdir = File.join @tempdir, "egd" gemdir = File.join @tempdir, "egd"
begin begin
FileUtils.rm_r gemdir FileUtils.rm_r gemdir
rescue rescue StandardError
nil nil
end end
refute File.exist?(gemdir), "manually remove #{gemdir}, tests are broken" refute File.exist?(gemdir), "manually remove #{gemdir}, tests are broken"
@ -702,7 +702,7 @@ class TestGem < Gem::TestCase
begin begin
FileUtils.rm_r parent FileUtils.rm_r parent
rescue rescue StandardError
nil nil
end end
refute File.exist?(parent), "manually remove #{parent}, tests are broken" refute File.exist?(parent), "manually remove #{parent}, tests are broken"
@ -1510,7 +1510,7 @@ class TestGem < Gem::TestCase
with_plugin("load") { Gem.load_env_plugins } with_plugin("load") { Gem.load_env_plugins }
begin begin
assert_equal :loaded, TEST_PLUGIN_LOAD assert_equal :loaded, TEST_PLUGIN_LOAD
rescue rescue StandardError
nil nil
end end
@ -1520,7 +1520,7 @@ class TestGem < Gem::TestCase
with_plugin("standarderror") { Gem.load_env_plugins } with_plugin("standarderror") { Gem.load_env_plugins }
begin begin
assert_equal :loaded, TEST_PLUGIN_STANDARDERROR assert_equal :loaded, TEST_PLUGIN_STANDARDERROR
rescue rescue StandardError
nil nil
end end
@ -1530,7 +1530,7 @@ class TestGem < Gem::TestCase
with_plugin("exception") { Gem.load_env_plugins } with_plugin("exception") { Gem.load_env_plugins }
begin begin
assert_equal :loaded, TEST_PLUGIN_EXCEPTION assert_equal :loaded, TEST_PLUGIN_EXCEPTION
rescue rescue StandardError
nil nil
end end
end end

View File

@ -732,7 +732,7 @@ class TestGemCommandsExecCommand < Gem::TestCase
begin begin
invoke "gem", "uninstall", "--verbose", "-x", "a" invoke "gem", "uninstall", "--verbose", "-x", "a"
rescue rescue StandardError
nil nil
end end
refute_includes @ui.output, "running gem exec with" refute_includes @ui.output, "running gem exec with"

View File

@ -157,7 +157,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@cmd.execute @cmd.execute
assert_equal false, File.exist?(formatted_executable) assert_equal false, File.exist?(formatted_executable)
rescue rescue StandardError
Gem::Installer.exec_format = nil Gem::Installer.exec_format = nil
end end

View File

@ -1567,7 +1567,7 @@ gem 'other', version
installer.install installer.install
end end
assert_path_exist so assert_path_exist so
rescue rescue StandardError
puts "-" * 78 puts "-" * 78
puts File.read File.join(@gemhome, "gems", "a-2", "Makefile") puts File.read File.join(@gemhome, "gems", "a-2", "Makefile")
puts "-" * 78 puts "-" * 78

View File

@ -363,7 +363,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
FileUtils.chmod 0555, @a1.cache_dir FileUtils.chmod 0555, @a1.cache_dir
begin begin
FileUtils.mkdir_p File.join(Gem.user_dir, "cache") FileUtils.mkdir_p File.join(Gem.user_dir, "cache")
rescue rescue StandardError
nil nil
end end
FileUtils.chmod 0555, File.join(Gem.user_dir, "cache") FileUtils.chmod 0555, File.join(Gem.user_dir, "cache")

View File

@ -3465,7 +3465,7 @@ Did you mean 'Ruby'?
capture_output do capture_output do
Gem::Specification.load(specfile.path) Gem::Specification.load(specfile.path)
end end
rescue => e rescue StandardError => e
name_rexp = Regexp.new(Regexp.escape(specfile.path)) name_rexp = Regexp.new(Regexp.escape(specfile.path))
assert e.backtrace.grep(name_rexp).any? assert e.backtrace.grep(name_rexp).any?
end end