Skip to content

Commit 4c9de7d

Browse files
authored
Merge pull request #19084 from Homebrew/add-comments-to-rubocop-disables
Add clarifying comments to `rubocop:disable`s
2 parents 730c93e + 9c8ff4c commit 4c9de7d

27 files changed

+43
-4
lines changed

Library/Homebrew/brew.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
end
201201

202202
exit 1
203+
# Catch any other types of exceptions.
203204
rescue Exception => e # rubocop:disable Lint/RescueException
204205
onoe e
205206

Library/Homebrew/build.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ def fixopt(formula)
230230
options = Options.create(args.flags_only)
231231
build = Build.new(formula, options, args:)
232232
build.install
233+
# Any exception means the build did not complete.
234+
# The `case` for what to do per-exception class is further down.
233235
rescue Exception => e # rubocop:disable Lint/RescueException
234236
error_hash = JSON.parse e.to_json
235237

Library/Homebrew/cask/dsl/depends_on.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def macos=(*args)
6363
MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: md[:comparator])
6464
elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*(?<version>\S+)\s*$/.match(first_arg))
6565
MacOSRequirement.new([md[:version]], comparator: md[:comparator])
66+
# This is not duplicate of the first case: see `args.first` and a different comparator.
6667
else # rubocop:disable Lint/DuplicateBranch
6768
MacOSRequirement.new([args.first], comparator: "==")
6869
end

Library/Homebrew/cmd/update-report.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ def migrate_tap_migration
626626
unless Formulary.factory(new_full_name).keg_only?
627627
system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite"
628628
end
629+
# Rescue any possible exception types.
629630
rescue Exception => e # rubocop:disable Lint/RescueException
630631
if Homebrew::EnvConfig.developer?
631632
require "utils/backtrace"

Library/Homebrew/dev-cmd/test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def run
9999
exec(*exec_args)
100100
end
101101
end
102+
# Rescue any possible exception types.
102103
rescue Exception => e # rubocop:disable Lint/RescueException
103104
retry if retry_test?(f)
104105

Library/Homebrew/download_queue.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(size = 1)
1919
sig { params(downloadable: Downloadable, force: T::Boolean).returns(Concurrent::Promises::Future) }
2020
def enqueue(downloadable, force: false)
2121
quiet = pool.max_length > 1
22-
# Passing in arguments from outside into the future is a common `concurrent-ruby` pattern.
22+
# Passing in arguments from outside into the future is a common `concurrent-ruby` pattern.
2323
# rubocop:disable Lint/ShadowingOuterLocalVariable
2424
Concurrent::Promises.future_on(pool, downloadable, force, quiet) do |downloadable, force, quiet|
2525
downloadable.clear_cache if force

Library/Homebrew/download_strategy.rbi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# typed: strict
22

3-
# This is a third-party implementation
3+
# This is a third-party implementation.
44
# rubocop:disable Lint/StructNewOverride
55
class Mechanize::HTTP
66
ContentDisposition = Struct.new :type, :filename, :creation_date,
77
:modification_date, :read_date, :size, :parameters
88
end
99
# rubocop:enable Lint/StructNewOverride
1010

11+
# This is a third-party implementation.
1112
# rubocop:disable Style/OptionalBooleanParameter
1213
class Mechanize::HTTP::ContentDispositionParser
1314
sig {

Library/Homebrew/extend/os/mac/readall.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def valid_casks?(tap, os_name: nil, arch: ::Hardware::CPU.type)
3131
raise "Missing URL" if cask.url.nil?
3232
rescue Interrupt
3333
raise
34+
# Handle all possible exceptions reading Casks.
3435
rescue Exception => e # rubocop:disable Lint/RescueException
3536
os_and_arch = "macOS #{current_macos_version} on #{arch}"
3637
onoe "Invalid cask (#{os_and_arch}): #{file}"

Library/Homebrew/formula.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,7 @@ def run_test(keep_tmp: false)
29032903
test
29042904
end
29052905
end
2906+
# Handle all possible exceptions running formula tests.
29062907
rescue Exception # rubocop:disable Lint/RescueException
29072908
staging.retain! if debug?
29082909
raise

Library/Homebrew/formula_installer.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ def install
484484
if pour_bottle?
485485
begin
486486
pour
487+
# Catch any other types of exceptions as they leave us with nothing installed.
487488
rescue Exception # rubocop:disable Lint/RescueException
488-
# any exceptions must leave us with nothing installed
489489
ignore_interrupts do
490490
begin
491491
FileUtils.rm_r(formula.prefix) if formula.prefix.directory?
@@ -825,6 +825,7 @@ def install_dependency(dep, inherited_options)
825825
oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}"
826826
fi.install
827827
fi.finish
828+
# Handle all possible exceptions installing deps.
828829
rescue Exception => e # rubocop:disable Lint/RescueException
829830
ignore_interrupts do
830831
tmp_keg.rename(installed_keg.to_path) if tmp_keg && !installed_keg.directory?
@@ -1022,6 +1023,7 @@ def build
10221023
formula.update_head_version
10231024

10241025
raise "Empty installation" if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation?
1026+
# Handle all possible exceptions when building.
10251027
rescue Exception => e # rubocop:disable Lint/RescueException
10261028
if e.is_a? BuildError
10271029
e.formula = formula
@@ -1099,6 +1101,7 @@ def link(keg)
10991101
puts "You can try again using:"
11001102
puts " brew link #{formula.name}"
11011103
@show_summary_heading = true
1104+
# Handle all other possible exceptions when linking.
11021105
rescue Exception => e # rubocop:disable Lint/RescueException
11031106
ofail "An unexpected error occurred during the `brew link` step"
11041107
puts "The formula built, but is not symlinked into #{HOMEBREW_PREFIX}"
@@ -1151,6 +1154,7 @@ def install_service
11511154
launchd_service_path.chmod 0644
11521155
log = formula.var/"log"
11531156
log.mkpath if service.include? log.to_s
1157+
# Handle all possible exceptions when installing service files.
11541158
rescue Exception => e # rubocop:disable Lint/RescueException
11551159
puts e
11561160
ofail "Failed to install service files"
@@ -1162,6 +1166,7 @@ def install_service
11621166
sig { params(keg: Keg).void }
11631167
def fix_dynamic_linkage(keg)
11641168
keg.fix_dynamic_linkage
1169+
# Rescue all possible exceptions when fixing linkage.
11651170
rescue Exception => e # rubocop:disable Lint/RescueException
11661171
ofail "Failed to fix install linkage"
11671172
puts "The formula built, but you may encounter issues using it or linking other"
@@ -1177,6 +1182,7 @@ def fix_dynamic_linkage(keg)
11771182
def clean
11781183
ohai "Cleaning" if verbose?
11791184
Cleaner.new(formula).clean
1185+
# Handle all possible exceptions when cleaning does not complete.
11801186
rescue Exception => e # rubocop:disable Lint/RescueException
11811187
opoo "The cleaning step did not complete successfully"
11821188
puts "Still, the installation was successful, so we will link it into your prefix."
@@ -1249,6 +1255,7 @@ def post_install
12491255
exec(*args)
12501256
end
12511257
end
1258+
# Handle all possible exceptions when postinstall does not complete.
12521259
rescue Exception => e # rubocop:disable Lint/RescueException
12531260
opoo "The post-install step did not complete successfully"
12541261
puts "You can try again using:"

0 commit comments

Comments
 (0)