@@ -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