diff --git a/Library/Homebrew/bottle_publisher.rb b/Library/Homebrew/bottle_publisher.rb index 5a59183e02..9911f99235 100644 --- a/Library/Homebrew/bottle_publisher.rb +++ b/Library/Homebrew/bottle_publisher.rb @@ -142,17 +142,15 @@ class BottlePublisher retry_count = 0 # We're in the cache; make sure to force re-download loop do - begin - curl_download url, to: filename - break - rescue - raise "Failed to download #{f} bottle from #{url}!" if retry_count >= max_curl_retries + curl_download url, to: filename + break + rescue + raise "Failed to download #{f} bottle from #{url}!" if retry_count >= max_curl_retries - puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec" - sleep curl_retry_delay_seconds - curl_retry_delay_seconds *= 2 - retry_count += 1 - end + puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec" + sleep curl_retry_delay_seconds + curl_retry_delay_seconds *= 2 + retry_count += 1 end checksum = Checksum.new(:sha256, bottle_info["sha256"]) Pathname.new(filename).verify_checksum(checksum) diff --git a/Library/Homebrew/cask/artifact/pkg.rb b/Library/Homebrew/cask/artifact/pkg.rb index 139a835714..b5414cf21f 100644 --- a/Library/Homebrew/cask/artifact/pkg.rb +++ b/Library/Homebrew/cask/artifact/pkg.rb @@ -65,13 +65,11 @@ module Cask return yield nil if choices.empty? Tempfile.open(["choices", ".xml"]) do |file| - begin - file.write Plist::Emit.dump(choices) - file.close - yield file.path - ensure - file.unlink - end + file.write Plist::Emit.dump(choices) + file.close + yield file.path + ensure + file.unlink end end end diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 15211e79e3..6c387c548b 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -19,11 +19,9 @@ module Cask return to_enum unless block_given? Tap.flat_map(&:cask_files).each do |f| - begin - yield CaskLoader::FromTapPathLoader.new(f).load - rescue CaskUnreadableError => e - opoo e.message - end + yield CaskLoader::FromTapPathLoader.new(f).load + rescue CaskUnreadableError => e + opoo e.message end end diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb index 3cc255bf69..23ffa9e44f 100644 --- a/Library/Homebrew/cask/cmd.rb +++ b/Library/Homebrew/cask/cmd.rb @@ -200,11 +200,9 @@ module Cask end remaining = all_args.select do |arg| - begin - !process_arguments([arg]).empty? - rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::AmbiguousOption - true - end + !process_arguments([arg]).empty? + rescue OptionParser::InvalidOption, OptionParser::MissingArgument, OptionParser::AmbiguousOption + true end remaining + non_options diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index 44a02ed00a..5c82efc12b 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -14,16 +14,14 @@ module Cask def run odie "Installing casks is supported only on macOS" unless OS.mac? casks.each do |cask| - begin - Installer.new(cask, binaries: binaries?, - verbose: verbose?, - force: force?, - skip_cask_deps: skip_cask_deps?, - require_sha: require_sha?, - quarantine: quarantine?).install - rescue CaskAlreadyInstalledError => e - opoo e.message - end + Installer.new(cask, binaries: binaries?, + verbose: verbose?, + force: force?, + skip_cask_deps: skip_cask_deps?, + require_sha: require_sha?, + quarantine: quarantine?).install + rescue CaskAlreadyInstalledError => e + opoo e.message end end diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index 968e8ca95f..3144a58072 100644 --- a/Library/Homebrew/cask/cmd/upgrade.rb +++ b/Library/Homebrew/cask/cmd/upgrade.rb @@ -45,12 +45,10 @@ module Cask return if dry_run? upgradable_casks.each do |(old_cask, new_cask)| - begin - upgrade_cask(old_cask, new_cask) - rescue CaskError => e - caught_exceptions << e - next - end + upgrade_cask(old_cask, new_cask) + rescue CaskError => e + caught_exceptions << e + next end return if caught_exceptions.empty? diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index eaceac0029..9ed09b4bb7 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -137,11 +137,9 @@ module Cask locales = MacOS.languages .map do |language| - begin - Locale.parse(language) - rescue Locale::ParserError - nil - end + Locale.parse(language) + rescue Locale::ParserError + nil end .compact @@ -255,18 +253,16 @@ module Cask ORDINARY_ARTIFACT_CLASSES.each do |klass| define_method(klass.dsl_key) do |*args| - begin - if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) && - (artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any? - raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.") - end - - artifacts.add(klass.from_args(cask, *args)) - rescue CaskInvalidError - raise - rescue => e - raise CaskInvalidError.new(cask, "invalid '#{klass.dsl_key}' stanza: #{e}") + if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) && + (artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any? + raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.") end + + artifacts.add(klass.from_args(cask, *args)) + rescue CaskInvalidError + raise + rescue => e + raise CaskInvalidError.new(cask, "invalid '#{klass.dsl_key}' stanza: #{e}") end end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index c517163950..96005c402e 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -111,12 +111,10 @@ module Cask return unless @cask.conflicts_with @cask.conflicts_with[:cask].each do |conflicting_cask| - begin - conflicting_cask = CaskLoader.load(conflicting_cask) - raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed? - rescue CaskUnavailableError - next # Ignore conflicting Casks that do not exist. - end + conflicting_cask = CaskLoader.load(conflicting_cask) + raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed? + rescue CaskUnavailableError + next # Ignore conflicting Casks that do not exist. end end diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 620f40dc79..1b05d33ca9 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -86,11 +86,9 @@ class Caveats def keg @keg ||= [f.prefix, f.opt_prefix, f.linked_keg].map do |d| - begin - Keg.new(d.resolved_path) - rescue - nil - end + Keg.new(d.resolved_path) + rescue + nil end.compact.first end diff --git a/Library/Homebrew/cmd/leaves.rb b/Library/Homebrew/cmd/leaves.rb index 6e5bd5ade6..246e9025c5 100644 --- a/Library/Homebrew/cmd/leaves.rb +++ b/Library/Homebrew/cmd/leaves.rb @@ -25,11 +25,9 @@ module Homebrew deps_of_installed = installed.flat_map do |f| f.runtime_dependencies.map do |dep| - begin - dep.to_formula.full_name - rescue FormulaUnavailableError - dep.name - end + dep.to_formula.full_name + rescue FormulaUnavailableError + dep.name end end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index e1488c2fd7..e2c736c686 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -382,21 +382,19 @@ module Homebrew end reinstallable.each do |f| - begin - reinstall_formula(f, build_from_source: true) - rescue FormulaInstallationAlreadyAttemptedError - # We already attempted to reinstall f as part of the dependency tree of - # another formula. In that case, don't generate an error, just move on. - nil - rescue CannotInstallFormulaError => e - ofail e - rescue BuildError => e - e.dump - puts - Homebrew.failed = true - rescue DownloadError => e - ofail e - end + reinstall_formula(f, build_from_source: true) + rescue FormulaInstallationAlreadyAttemptedError + # We already attempted to reinstall f as part of the dependency tree of + # another formula. In that case, don't generate an error, just move on. + nil + rescue CannotInstallFormulaError => e + ofail e + rescue BuildError => e + e.dump + puts + Homebrew.failed = true + rescue DownloadError => e + ofail e end end end diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 1aa9471400..25bb991a17 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -68,26 +68,22 @@ module Homebrew uses = formulae.select do |f| used_formulae.all? do |ff| - begin - deps = f.runtime_dependencies if only_installed_arg - deps ||= if recursive - recursive_includes(Dependency, f, includes, ignores) - else - reject_ignores(f.deps, ignores, includes) - end - - deps.any? do |dep| - begin - dep.to_formula.full_name == ff.full_name - rescue - dep.name == ff.name - end - end - rescue FormulaUnavailableError - # Silently ignore this case as we don't care about things used in - # taps that aren't currently tapped. - next + deps = f.runtime_dependencies if only_installed_arg + deps ||= if recursive + recursive_includes(Dependency, f, includes, ignores) + else + reject_ignores(f.deps, ignores, includes) end + + deps.any? do |dep| + dep.to_formula.full_name == ff.full_name + rescue + dep.name == ff.name + end + rescue FormulaUnavailableError + # Silently ignore this case as we don't care about things used in + # taps that aren't currently tapped. + next end end diff --git a/Library/Homebrew/description_cache_store.rb b/Library/Homebrew/description_cache_store.rb index b507aed6bd..93138181ab 100644 --- a/Library/Homebrew/description_cache_store.rb +++ b/Library/Homebrew/description_cache_store.rb @@ -63,11 +63,9 @@ class DescriptionCacheStore < CacheStore return populate_if_empty! if database.empty? formula_names.each do |name| - begin - update!(name, Formula[name].desc) - rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS - delete!(name) - end + update!(name, Formula[name].desc) + rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS + delete!(name) end end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index b93cd0846e..92bd38ab81 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -434,16 +434,14 @@ module Homebrew def audit_conflicts formula.conflicts.each do |c| - begin - Formulary.factory(c.name) - rescue TapFormulaUnavailableError - # Don't complain about missing cross-tap conflicts. - next - rescue FormulaUnavailableError - problem "Can't find conflicting formula #{c.name.inspect}." - rescue TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError - problem "Ambiguous conflicting formula #{c.name.inspect}." - end + Formulary.factory(c.name) + rescue TapFormulaUnavailableError + # Don't complain about missing cross-tap conflicts. + next + rescue FormulaUnavailableError + problem "Can't find conflicting formula #{c.name.inspect}." + rescue TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError + problem "Ambiguous conflicting formula #{c.name.inspect}." end end diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 94f412e9a5..8b142d7819 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -718,15 +718,13 @@ module Homebrew def check_for_unreadable_installed_formula formula_unavailable_exceptions = [] Formula.racks.each do |rack| - begin - Formulary.from_rack(rack) - rescue FormulaUnreadableError, FormulaClassUnavailableError, - TapFormulaUnreadableError, TapFormulaClassUnavailableError => e - formula_unavailable_exceptions << e - rescue FormulaUnavailableError, - TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError - nil - end + Formulary.from_rack(rack) + rescue FormulaUnreadableError, FormulaClassUnavailableError, + TapFormulaUnreadableError, TapFormulaClassUnavailableError => e + formula_unavailable_exceptions << e + rescue FormulaUnavailableError, + TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError + nil end return if formula_unavailable_exceptions.empty? diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 2ff175cde5..1170f45bcb 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -213,11 +213,9 @@ module SharedEnvExtension path.append( # user paths ORIGINAL_PATHS.map do |p| - begin - p.realpath.to_s - rescue - nil - end + p.realpath.to_s + rescue + nil end - %w[/usr/X11/bin /opt/X11/bin], ) self["PATH"] = path diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index 94eb819d6e..fe11864c4c 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -17,12 +17,10 @@ module Superenv def homebrew_extra_paths paths = [] paths += %w[binutils make].map do |f| - begin - bin = Formula[f].opt_bin - bin if bin.directory? - rescue FormulaUnavailableError - nil - end + bin = Formula[f].opt_bin + bin if bin.directory? + rescue FormulaUnavailableError + nil end.compact paths end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6c96550ac2..8c70bd22e7 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -387,11 +387,9 @@ class Formula return [] if versioned_formula? Pathname.glob(path.to_s.gsub(/\.rb$/, "@*.rb")).map do |path| - begin - Formula[path.basename(".rb").to_s] - rescue FormulaUnavailableError - nil - end + Formula[path.basename(".rb").to_s] + rescue FormulaUnavailableError + nil end.compact.sort end @@ -1387,14 +1385,12 @@ class Formula # @private def self.each files.each do |file| - begin - yield Formulary.factory(file) - rescue => e - # Don't let one broken formula break commands. But do complain. - onoe "Failed to import: #{file}" - puts e - next - end + yield Formulary.factory(file) + rescue => e + # Don't let one broken formula break commands. But do complain. + onoe "Failed to import: #{file}" + puts e + next end end @@ -1425,11 +1421,9 @@ class Formula # @private def self.installed @installed ||= racks.flat_map do |rack| - begin - Formulary.from_rack(rack) - rescue - [] - end + Formulary.from_rack(rack) + rescue + [] end.uniq(&:name) end @@ -1568,11 +1562,9 @@ class Formula read_from_tab: read_from_tab, undeclared: undeclared, ).map do |d| - begin - d.to_formula - rescue FormulaUnavailableError - nil - end + d.to_formula + rescue FormulaUnavailableError + nil end.compact end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 90b431735c..dbfa5f1d3b 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -351,28 +351,26 @@ class FormulaInstaller return if ARGV.force? conflicts = formula.conflicts.select do |c| - begin - f = Formulary.factory(c.name) - rescue TapFormulaUnavailableError - # If the formula name is a fully-qualified name let's silently - # ignore it as we don't care about things used in taps that aren't - # currently tapped. - false - rescue FormulaUnavailableError => e - # If the formula name doesn't exist any more then complain but don't - # stop installation from continuing. - opoo <<~EOS + f = Formulary.factory(c.name) + rescue TapFormulaUnavailableError + # If the formula name is a fully-qualified name let's silently + # ignore it as we don't care about things used in taps that aren't + # currently tapped. + false + rescue FormulaUnavailableError => e + # If the formula name doesn't exist any more then complain but don't + # stop installation from continuing. + opoo <<~EOS #{formula}: #{e.message} 'conflicts_with \"#{c.name}\"' should be removed from #{formula.path.basename}. EOS - raise if ARGV.homebrew_developer? + raise if ARGV.homebrew_developer? - $stderr.puts "Please report this to the #{formula.tap} tap!" - false - else - f.linked_keg.exist? && f.opt_prefix.exist? - end + $stderr.puts "Please report this to the #{formula.tap} tap!" + false + else + f.linked_keg.exist? && f.opt_prefix.exist? end raise FormulaConflictError.new(formula, conflicts) unless conflicts.empty? diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 2b4e4a867f..a86bbc4ade 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -106,11 +106,9 @@ require "PATH" ENV["HOMEBREW_PATH"] ||= ENV["PATH"] ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).map do |p| - begin - Pathname.new(p).expand_path - rescue - nil - end + Pathname.new(p).expand_path +rescue + nil end.compact.freeze HOMEBREW_INTERNAL_COMMAND_ALIASES = { diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 1d07053e03..86d63161f3 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -22,17 +22,15 @@ module Homebrew def attempt_directory_creation Keg::MUST_EXIST_DIRECTORIES.each do |dir| - begin - FileUtils.mkdir_p(dir) unless dir.exist? + FileUtils.mkdir_p(dir) unless dir.exist? - # Create these files to ensure that these directories aren't removed - # by the Catalina installer. - # (https://github.com/Homebrew/brew/issues/6263) - keep_file = dir/".keepme" - FileUtils.touch(keep_file) unless keep_file.exist? - rescue - nil - end + # Create these files to ensure that these directories aren't removed + # by the Catalina installer. + # (https://github.com/Homebrew/brew/issues/6263) + keep_file = dir/".keepme" + FileUtils.touch(keep_file) unless keep_file.exist? + rescue + nil end end diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 4187ad6445..ab88502023 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -128,17 +128,15 @@ class Keg keg_names = kegs.select(&:optlinked?).map(&:name) keg_formulae = [] kegs_by_source = kegs.group_by do |keg| - begin # First, attempt to resolve the keg to a formula # to get up-to-date name and tap information. - f = keg.to_formula - keg_formulae << f - [f.name, f.tap] - rescue FormulaUnavailableError - # If the formula for the keg can't be found, - # fall back to the information in the tab. - [keg.name, keg.tab.tap] - end + f = keg.to_formula + keg_formulae << f + [f.name, f.tap] + rescue FormulaUnavailableError + # If the formula for the keg can't be found, + # fall back to the information in the tab. + [keg.name, keg.tab.tap] end all_required_kegs = Set.new diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index 327bcef52f..54c74c01aa 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -37,15 +37,13 @@ module Readall def valid_formulae?(formulae) failed = false formulae.each do |file| - begin - Formulary.factory(file) - rescue Interrupt - raise - rescue Exception => e # rubocop:disable Lint/RescueException - onoe "Invalid formula: #{file}" - puts e - failed = true - end + Formulary.factory(file) + rescue Interrupt + raise + rescue Exception => e # rubocop:disable Lint/RescueException + onoe "Invalid formula: #{file}" + puts e + failed = true end !failed end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 5beee67ca7..6d4be08707 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -184,13 +184,11 @@ class SoftwareSpec def recursive_dependencies deps_f = [] recursive_dependencies = deps.map do |dep| - begin - deps_f << dep.to_formula - dep - rescue TapFormulaUnavailableError - # Don't complain about missing cross-tap dependencies - next - end + deps_f << dep.to_formula + dep + rescue TapFormulaUnavailableError + # Don't complain about missing cross-tap dependencies + next end.compact.uniq deps_f.compact.each do |f| f.recursive_dependencies.each do |dep| @@ -386,11 +384,10 @@ class BottleSpecification def checksums tags = collector.keys.sort_by do |tag| # Sort non-MacOS tags below MacOS tags. - begin - OS::Mac::Version.from_symbol tag - rescue ArgumentError - "0.#{tag}" - end + + OS::Mac::Version.from_symbol tag + rescue ArgumentError + "0.#{tag}" end checksums = {} tags.reverse_each do |tag| diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index f7ccf88331..c1ede4a6ee 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -148,13 +148,11 @@ class SystemCommand break if readable_sources.empty? readable_sources.each do |source| - begin - line = source.readline_nonblock || "" - type = (source == sources[0]) ? :stdout : :stderr - yield(type, line) - rescue IO::WaitReadable, EOFError - next - end + line = source.readline_nonblock || "" + type = (source == sources[0]) ? :stdout : :stderr + yield(type, line) + rescue IO::WaitReadable, EOFError + next end end diff --git a/Library/Homebrew/test/cask/artifact/shared_examples/uninstall_zap.rb b/Library/Homebrew/test/cask/artifact/shared_examples/uninstall_zap.rb index 7e57322ffa..91eff61b6f 100644 --- a/Library/Homebrew/test/cask/artifact/shared_examples/uninstall_zap.rb +++ b/Library/Homebrew/test/cask/artifact/shared_examples/uninstall_zap.rb @@ -199,15 +199,13 @@ shared_examples "#uninstall_phase or #zap_phase" do let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-#{directive}")) } around do |example| - begin - ENV["HOME"] = dir + ENV["HOME"] = dir - FileUtils.touch paths + FileUtils.touch paths - example.run - ensure - FileUtils.rm_f paths - end + example.run + ensure + FileUtils.rm_f paths end before do diff --git a/Library/Homebrew/test/cask/cmd/create_spec.rb b/Library/Homebrew/test/cask/cmd/create_spec.rb index 2effe846c9..3892266be8 100644 --- a/Library/Homebrew/test/cask/cmd/create_spec.rb +++ b/Library/Homebrew/test/cask/cmd/create_spec.rb @@ -5,12 +5,10 @@ require_relative "shared_examples/invalid_option" describe Cask::Cmd::Create, :cask do around do |example| - begin - example.run - ensure - %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask| - FileUtils.rm_f Cask::CaskLoader.path(cask) - end + example.run + ensure + %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask| + FileUtils.rm_f Cask::CaskLoader.path(cask) end end diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 77f0d3723e..f2bfd2b1f6 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -473,18 +473,16 @@ describe Cask::DSL, :cask do end it "does not include a trailing slash" do - begin - original_appdir = Cask::Config.global.appdir - Cask::Config.global.appdir = "#{original_appdir}/" + original_appdir = Cask::Config.global.appdir + Cask::Config.global.appdir = "#{original_appdir}/" - cask = Cask::Cask.new("appdir-trailing-slash") do - binary "#{appdir}/some/path" - end - - expect(cask.artifacts.first.source).to eq(original_appdir/"some/path") - ensure - Cask::Config.global.appdir = original_appdir + cask = Cask::Cask.new("appdir-trailing-slash") do + binary "#{appdir}/some/path" end + + expect(cask.artifacts.first.source).to eq(original_appdir/"some/path") + ensure + Cask::Config.global.appdir = original_appdir end end diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index ce6a0f21f9..91d893ca1f 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -34,15 +34,13 @@ describe Homebrew::Cleanup do let(:lock_file) { Pathname.new("#{HOMEBREW_LOCKS}/foo") } around do |example| - begin - FileUtils.touch ds_store - FileUtils.touch lock_file + FileUtils.touch ds_store + FileUtils.touch lock_file - example.run - ensure - FileUtils.rm_f ds_store - FileUtils.rm_f lock_file - end + example.run + ensure + FileUtils.rm_f ds_store + FileUtils.rm_f lock_file end describe "::cleanup" do diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index 7091a345e0..2a1c18fe5f 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -33,15 +33,13 @@ RSpec.shared_context "custom internal commands" do end around do |example| - begin - cmds.each do |f| - FileUtils.touch f - end - - example.run - ensure - FileUtils.rm_f cmds + cmds.each do |f| + FileUtils.touch f end + + example.run + ensure + FileUtils.rm_f cmds end end diff --git a/Library/Homebrew/test/cmd/style_spec.rb b/Library/Homebrew/test/cmd/style_spec.rb index 0dcb681702..51d64d807f 100644 --- a/Library/Homebrew/test/cmd/style_spec.rb +++ b/Library/Homebrew/test/cmd/style_spec.rb @@ -9,17 +9,15 @@ end describe "brew style" do around do |example| - begin - FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew" - FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml" - FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml" + FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew" + FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml" + FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop_shared.yml", HOMEBREW_LIBRARY/".rubocop_shared.yml" - example.run - ensure - FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew" - FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml" - FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml" - end + example.run + ensure + FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew" + FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml" + FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_shared.yml" end before do diff --git a/Library/Homebrew/test/diagnostic_checks_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb index 0852dcfd7c..95f22b1d2a 100644 --- a/Library/Homebrew/test/diagnostic_checks_spec.rb +++ b/Library/Homebrew/test/diagnostic_checks_spec.rb @@ -73,20 +73,18 @@ describe Homebrew::Diagnostic::Checks do end specify "#check_user_path_3" do - begin - sbin = HOMEBREW_PREFIX/"sbin" - ENV["HOMEBREW_PATH"] = - "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" + - ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "") - (sbin/"something").mkpath + sbin = HOMEBREW_PREFIX/"sbin" + ENV["HOMEBREW_PATH"] = + "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" + + ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "") + (sbin/"something").mkpath - expect(subject.check_user_path_1).to be nil - expect(subject.check_user_path_2).to be nil - expect(subject.check_user_path_3) - .to match("Homebrew's sbin was not found in your PATH") - ensure - sbin.rmtree - end + expect(subject.check_user_path_1).to be nil + expect(subject.check_user_path_2).to be nil + expect(subject.check_user_path_3) + .to match("Homebrew's sbin was not found in your PATH") + ensure + sbin.rmtree end specify "#check_for_config_scripts" do @@ -103,18 +101,16 @@ describe Homebrew::Diagnostic::Checks do end specify "#check_for_symlinked_cellar" do - begin - HOMEBREW_CELLAR.rmtree + HOMEBREW_CELLAR.rmtree - mktmpdir do |path| - FileUtils.ln_s path, HOMEBREW_CELLAR + mktmpdir do |path| + FileUtils.ln_s path, HOMEBREW_CELLAR - expect(subject.check_for_symlinked_cellar).to match(path) - end - ensure - HOMEBREW_CELLAR.unlink - HOMEBREW_CELLAR.mkpath + expect(subject.check_for_symlinked_cellar).to match(path) end + ensure + HOMEBREW_CELLAR.unlink + HOMEBREW_CELLAR.mkpath end specify "#check_ld_vars catches LD vars" do diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index b762115950..90589e7f22 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -1266,42 +1266,40 @@ describe Formula do let(:testball_repo) { HOMEBREW_PREFIX/"testball_repo" } example do - begin - outdated_stable_prefix = HOMEBREW_CELLAR/"testball/1.0" - head_prefix_a = HOMEBREW_CELLAR/"testball/HEAD" - head_prefix_b = HOMEBREW_CELLAR/"testball/HEAD-aaaaaaa_1" - head_prefix_c = HOMEBREW_CELLAR/"testball/HEAD-18a7103" + outdated_stable_prefix = HOMEBREW_CELLAR/"testball/1.0" + head_prefix_a = HOMEBREW_CELLAR/"testball/HEAD" + head_prefix_b = HOMEBREW_CELLAR/"testball/HEAD-aaaaaaa_1" + head_prefix_c = HOMEBREW_CELLAR/"testball/HEAD-18a7103" - setup_tab_for_prefix(outdated_stable_prefix) - tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" }) - setup_tab_for_prefix(head_prefix_b) + setup_tab_for_prefix(outdated_stable_prefix) + tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" }) + setup_tab_for_prefix(head_prefix_b) - testball_repo.mkdir - testball_repo.cd do - FileUtils.touch "LICENSE" + testball_repo.mkdir + testball_repo.cd do + FileUtils.touch "LICENSE" - system("git", "init") - system("git", "add", "--all") - system("git", "commit", "-m", "Initial commit") - end - - expect(f.outdated_kegs(fetch_head: true)).not_to be_empty - - tab_a.source["versions"] = { "stable" => f.version.to_s } - tab_a.write - reset_outdated_kegs - expect(f.outdated_kegs(fetch_head: true)).not_to be_empty - - head_prefix_a.rmtree - reset_outdated_kegs - expect(f.outdated_kegs(fetch_head: true)).not_to be_empty - - setup_tab_for_prefix(head_prefix_c, source_modified_time: 1) - reset_outdated_kegs - expect(f.outdated_kegs(fetch_head: true)).to be_empty - ensure - testball_repo.rmtree if testball_repo.exist? + system("git", "init") + system("git", "add", "--all") + system("git", "commit", "-m", "Initial commit") end + + expect(f.outdated_kegs(fetch_head: true)).not_to be_empty + + tab_a.source["versions"] = { "stable" => f.version.to_s } + tab_a.write + reset_outdated_kegs + expect(f.outdated_kegs(fetch_head: true)).not_to be_empty + + head_prefix_a.rmtree + reset_outdated_kegs + expect(f.outdated_kegs(fetch_head: true)).not_to be_empty + + setup_tab_for_prefix(head_prefix_c, source_modified_time: 1) + reset_outdated_kegs + expect(f.outdated_kegs(fetch_head: true)).to be_empty + ensure + testball_repo.rmtree if testball_repo.exist? end end diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index de2576c676..7da63374ba 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -217,11 +217,9 @@ RSpec::Matchers.alias_matcher :a_string_containing, :include RSpec::Matchers.define :a_json_string do match do |actual| - begin - JSON.parse(actual) - true - rescue JSON::ParserError - false - end + JSON.parse(actual) + true + rescue JSON::ParserError + false end end diff --git a/Library/Homebrew/test/support/helper/cask/fake_system_command.rb b/Library/Homebrew/test/support/helper/cask/fake_system_command.rb index 253e9c8e86..47080e6419 100644 --- a/Library/Homebrew/test/support/helper/cask/fake_system_command.rb +++ b/Library/Homebrew/test/support/helper/cask/fake_system_command.rb @@ -66,10 +66,8 @@ end RSpec.configure do |config| config.after do - begin - FakeSystemCommand.verify_expectations! - ensure - FakeSystemCommand.clear - end + FakeSystemCommand.verify_expectations! + ensure + FakeSystemCommand.clear end end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index b61a0b0c14..f7731bbd54 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -41,14 +41,12 @@ RSpec.shared_context "integration test" do end around do |example| - begin - (HOMEBREW_PREFIX/"bin").mkpath - FileUtils.touch HOMEBREW_PREFIX/"bin/brew" + (HOMEBREW_PREFIX/"bin").mkpath + FileUtils.touch HOMEBREW_PREFIX/"bin/brew" - example.run - ensure - FileUtils.rm_r HOMEBREW_PREFIX/"bin" - end + example.run + ensure + FileUtils.rm_r HOMEBREW_PREFIX/"bin" end # Generate unique ID to be able to @@ -94,11 +92,9 @@ RSpec.shared_context "integration test" do simplecov_spec = Gem.loaded_specs["simplecov"] specs = [simplecov_spec] simplecov_spec.runtime_dependencies.each do |dep| - begin - specs += dep.to_specs - rescue Gem::LoadError => e - onoe e - end + specs += dep.to_specs + rescue Gem::LoadError => e + onoe e end libs = specs.flat_map do |spec| full_gem_path = spec.full_gem_path diff --git a/Library/Homebrew/test/system_command_spec.rb b/Library/Homebrew/test/system_command_spec.rb index a10b4f485a..3be1f4aa20 100644 --- a/Library/Homebrew/test/system_command_spec.rb +++ b/Library/Homebrew/test/system_command_spec.rb @@ -267,14 +267,12 @@ describe SystemCommand do it "does not leak the secrets set by environment" do redacted_msg = /#{Regexp.escape("username:******")}/ expect do - begin - ENV["PASSWORD"] = "hunter2" - described_class.run! "curl", - args: %w[--user username:hunter2], - verbose: true - ensure - ENV.delete "PASSWORD" - end + ENV["PASSWORD"] = "hunter2" + described_class.run! "curl", + args: %w[--user username:hunter2], + verbose: true + ensure + ENV.delete "PASSWORD" end.to raise_error.with_message(redacted_msg).and output(redacted_msg).to_stdout end end diff --git a/Library/Homebrew/test/tap_spec.rb b/Library/Homebrew/test/tap_spec.rb index 90ebbb2be4..92cd33d478 100644 --- a/Library/Homebrew/test/tap_spec.rb +++ b/Library/Homebrew/test/tap_spec.rb @@ -61,27 +61,25 @@ describe Tap do end specify "::fetch" do - begin - expect(described_class.fetch("Homebrew", "core")).to be_kind_of(CoreTap) - expect(described_class.fetch("Homebrew", "homebrew")).to be_kind_of(CoreTap) - tap = described_class.fetch("Homebrew", "foo") - expect(tap).to be_kind_of(described_class) - expect(tap.name).to eq("homebrew/foo") + expect(described_class.fetch("Homebrew", "core")).to be_kind_of(CoreTap) + expect(described_class.fetch("Homebrew", "homebrew")).to be_kind_of(CoreTap) + tap = described_class.fetch("Homebrew", "foo") + expect(tap).to be_kind_of(described_class) + expect(tap.name).to eq("homebrew/foo") - expect { - described_class.fetch("foo") - }.to raise_error(/Invalid tap name/) + expect { + described_class.fetch("foo") + }.to raise_error(/Invalid tap name/) - expect { - described_class.fetch("homebrew/homebrew/bar") - }.to raise_error(/Invalid tap name/) + expect { + described_class.fetch("homebrew/homebrew/bar") + }.to raise_error(/Invalid tap name/) - expect { - described_class.fetch("homebrew", "homebrew/baz") - }.to raise_error(/Invalid tap name/) - ensure - described_class.clear_cache - end + expect { + described_class.fetch("homebrew", "homebrew/baz") + }.to raise_error(/Invalid tap name/) + ensure + described_class.clear_cache end describe "::from_path" do @@ -113,23 +111,21 @@ describe Tap do end specify "#issues_url" do - begin - t = described_class.new("someone", "foo") - path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" - path.mkpath - cd path do - system "git", "init" - system "git", "remote", "add", "origin", - "https://github.com/someone/homebrew-foo" - end - expect(t.issues_url).to eq("https://github.com/someone/homebrew-foo/issues") - expect(subject.issues_url).to eq("https://github.com/Homebrew/homebrew-foo/issues") - - (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath - expect(described_class.new("someone", "no-git").issues_url).to be nil - ensure - path.parent.rmtree + t = described_class.new("someone", "foo") + path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" + path.mkpath + cd path do + system "git", "init" + system "git", "remote", "add", "origin", + "https://github.com/someone/homebrew-foo" end + expect(t.issues_url).to eq("https://github.com/someone/homebrew-foo/issues") + expect(subject.issues_url).to eq("https://github.com/Homebrew/homebrew-foo/issues") + + (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath + expect(described_class.new("someone", "no-git").issues_url).to be nil + ensure + path.parent.rmtree end specify "files" do @@ -272,53 +268,49 @@ describe Tap do end specify "#install and #uninstall" do - begin - setup_tap_files - setup_git_repo + setup_tap_files + setup_git_repo - tap = described_class.new("Homebrew", "bar") + tap = described_class.new("Homebrew", "bar") - tap.install clone_target: subject.path/".git" + tap.install clone_target: subject.path/".git" - expect(tap).to be_installed - expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file - expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file - expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file - expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file - tap.uninstall + expect(tap).to be_installed + expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file + expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file + expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file + expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file + tap.uninstall - expect(tap).not_to be_installed - expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").not_to exist - expect(HOMEBREW_PREFIX/"share/man/man1").not_to exist - expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").not_to exist - expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").not_to exist - expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").not_to exist - ensure - (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? - (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? - end + expect(tap).not_to be_installed + expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").not_to exist + expect(HOMEBREW_PREFIX/"share/man/man1").not_to exist + expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").not_to exist + expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").not_to exist + expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").not_to exist + ensure + (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? + (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? end specify "#link_completions_and_manpages" do - begin - setup_tap_files - setup_git_repo - tap = described_class.new("Homebrew", "baz") - tap.install clone_target: subject.path/".git" - (HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete - (HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete - (HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete - (HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").delete - tap.link_completions_and_manpages - expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file - expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file - expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file - expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file - tap.uninstall - ensure - (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? - (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? - end + setup_tap_files + setup_git_repo + tap = described_class.new("Homebrew", "baz") + tap.install clone_target: subject.path/".git" + (HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").delete + (HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").delete + (HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").delete + (HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").delete + tap.link_completions_and_manpages + expect(HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1").to be_a_file + expect(HOMEBREW_PREFIX/"etc/bash_completion.d/brew-tap-cmd").to be_a_file + expect(HOMEBREW_PREFIX/"share/zsh/site-functions/_brew-tap-cmd").to be_a_file + expect(HOMEBREW_PREFIX/"share/fish/vendor_completions.d/brew-tap-cmd.fish").to be_a_file + tap.uninstall + ensure + (HOMEBREW_PREFIX/"etc").rmtree if (HOMEBREW_PREFIX/"etc").exist? + (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? end specify "#pin and #unpin" do diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 3a54611e79..cb946f624e 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -50,13 +50,11 @@ module Homebrew method = instance_method(name) define_method(name) do |*args, &block| - begin - time = Time.now - method.bind(self).call(*args, &block) - ensure - $times[name] ||= 0 - $times[name] += Time.now - time - end + time = Time.now + method.bind(self).call(*args, &block) + ensure + $times[name] ||= 0 + $times[name] += Time.now - time end end end @@ -388,11 +386,9 @@ module Kernel def paths @paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p| - begin - File.expand_path(p).chomp("/") - rescue ArgumentError - onoe "The following PATH component is invalid: #{p}" - end + File.expand_path(p).chomp("/") + rescue ArgumentError + onoe "The following PATH component is invalid: #{p}" end.uniq.compact end diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index df67c7cf48..29f9acbaf6 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -32,31 +32,29 @@ module Utils read, write = IO.pipe pid = fork do - begin - ENV["HOMEBREW_ERROR_PIPE"] = server.path - server.close - read.close - write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) - yield - rescue Exception => e # rubocop:disable Lint/RescueException - error_hash = JSON.parse e.to_json + ENV["HOMEBREW_ERROR_PIPE"] = server.path + server.close + read.close + write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + yield + rescue Exception => e # rubocop:disable Lint/RescueException + error_hash = JSON.parse e.to_json - # Special case: We need to recreate ErrorDuringExecutions - # for proper error messages and because other code expects - # to rescue them further down. - if e.is_a?(ErrorDuringExecution) - error_hash["cmd"] = e.cmd - error_hash["status"] = e.status.exitstatus - error_hash["output"] = e.output - end - - write.puts error_hash.to_json - write.close - - exit! - else - exit!(true) + # Special case: We need to recreate ErrorDuringExecutions + # for proper error messages and because other code expects + # to rescue them further down. + if e.is_a?(ErrorDuringExecution) + error_hash["cmd"] = e.cmd + error_hash["status"] = e.status.exitstatus + error_hash["output"] = e.output end + + write.puts error_hash.to_json + write.close + + exit! + else + exit!(true) end ignore_interrupts(:quietly) do # the child will receive the interrupt and marshal it back