Add utils/backtrace requires

This is primarily intended to resolve the `uninitialized constant
Utils::Backtrace` error in `formula_versions.rb:60` but I expanded it
to try to cover all existing usage of `Utils::Backtrace`.

I've followed the existing pattern, where `utils/backtrace` is
required in the context of where it's used. Many of these cases use
`Backtrace` in a conditional manner, so I've tried to ensure that the
`require` follows suit.
This commit is contained in:
Sam Ford 2024-07-15 13:44:01 -04:00
parent cb48a95bbd
commit 11d6785bea
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D
7 changed files with 52 additions and 11 deletions

View File

@ -147,8 +147,10 @@ rescue UsageError => e
Homebrew::Help.help cmd, remaining_args: args&.remaining, usage_error: e.message Homebrew::Help.help cmd, remaining_args: args&.remaining, usage_error: e.message
rescue SystemExit => e rescue SystemExit => e
onoe "Kernel.exit" if args&.debug? && !e.success? onoe "Kernel.exit" if args&.debug? && !e.success?
require "utils/backtrace" if args&.debug? || ARGV.include?("--debug")
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug") require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e)
end
raise raise
rescue Interrupt rescue Interrupt
$stderr.puts # seemingly a newline is typical $stderr.puts # seemingly a newline is typical
@ -185,8 +187,10 @@ rescue RuntimeError, SystemCallError => e
raise if e.message.empty? raise if e.message.empty?
onoe e onoe e
require "utils/backtrace" if args&.debug? || ARGV.include?("--debug")
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug") require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e)
end
exit 1 exit 1
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException

View File

@ -174,7 +174,10 @@ module Homebrew
begin begin
reporter = Reporter.new(tap) reporter = Reporter.new(tap)
rescue Reporter::ReporterRevisionUnsetError => e rescue Reporter::ReporterRevisionUnsetError => e
onoe "#{e.message}\n#{Utils::Backtrace.clean(e)&.join("\n")}" if Homebrew::EnvConfig.developer? if Homebrew::EnvConfig.developer?
require "utils/backtrace"
onoe "#{e.message}\n#{Utils::Backtrace.clean(e)&.join("\n")}"
end
next next
end end
if reporter.updated? if reporter.updated?
@ -624,7 +627,10 @@ class Reporter
system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite" system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite"
end end
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "#{e.message}\n#{Utils::Backtrace.clean(e)&.join("\n")}" if Homebrew::EnvConfig.developer? if Homebrew::EnvConfig.developer?
require "utils/backtrace"
onoe "#{e.message}\n#{Utils::Backtrace.clean(e)&.join("\n")}"
end
end end
next next
end end

View File

@ -1034,7 +1034,12 @@ on_request: installed_on_request?, options:)
ofail "An unexpected error occurred during the `brew link` step" ofail "An unexpected error occurred during the `brew link` step"
puts "The formula built, but is not symlinked into #{HOMEBREW_PREFIX}" puts "The formula built, but is not symlinked into #{HOMEBREW_PREFIX}"
puts e puts e
puts Utils::Backtrace.clean(e) if debug?
if debug?
require "utils/backtrace"
puts Utils::Backtrace.clean(e)
end
@show_summary_heading = true @show_summary_heading = true
ignore_interrupts do ignore_interrupts do
keg.unlink keg.unlink
@ -1080,6 +1085,8 @@ on_request: installed_on_request?, options:)
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
puts e puts e
ofail "Failed to install service files" ofail "Failed to install service files"
require "utils/backtrace"
odebug e, Utils::Backtrace.clean(e) odebug e, Utils::Backtrace.clean(e)
end end
@ -1090,7 +1097,10 @@ on_request: installed_on_request?, options:)
ofail "Failed to fix install linkage" ofail "Failed to fix install linkage"
puts "The formula built, but you may encounter issues using it or linking other" puts "The formula built, but you may encounter issues using it or linking other"
puts "formulae against it." puts "formulae against it."
require "utils/backtrace"
odebug e, Utils::Backtrace.clean(e) odebug e, Utils::Backtrace.clean(e)
@show_summary_heading = true @show_summary_heading = true
end end
@ -1101,7 +1111,10 @@ on_request: installed_on_request?, options:)
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
opoo "The cleaning step did not complete successfully" opoo "The cleaning step did not complete successfully"
puts "Still, the installation was successful, so we will link it into your prefix." puts "Still, the installation was successful, so we will link it into your prefix."
require "utils/backtrace"
odebug e, Utils::Backtrace.clean(e) odebug e, Utils::Backtrace.clean(e)
Homebrew.failed = true Homebrew.failed = true
@show_summary_heading = true @show_summary_heading = true
end end
@ -1171,7 +1184,10 @@ on_request: installed_on_request?, options:)
opoo "The post-install step did not complete successfully" opoo "The post-install step did not complete successfully"
puts "You can try again using:" puts "You can try again using:"
puts " brew postinstall #{formula.full_name}" puts " brew postinstall #{formula.full_name}"
require "utils/backtrace"
odebug e, Utils::Backtrace.clean(e), always_display: Homebrew::EnvConfig.developer? odebug e, Utils::Backtrace.clean(e), always_display: Homebrew::EnvConfig.developer?
Homebrew.failed = true Homebrew.failed = true
@show_summary_heading = true @show_summary_heading = true
end end

View File

@ -55,6 +55,8 @@ class FormulaVersions
nostdout { Formulary.from_contents(name, path, contents, ignore_errors: true) } nostdout { Formulary.from_contents(name, path, contents, ignore_errors: true) }
end end
rescue *IGNORED_EXCEPTIONS => e rescue *IGNORED_EXCEPTIONS => e
require "utils/backtrace"
# We rescue these so that we can skip bad versions and # We rescue these so that we can skip bad versions and
# continue walking the history # continue walking the history
odebug "#{e} in #{name} at revision #{revision}", Utils::Backtrace.clean(e) odebug "#{e} in #{name} at revision #{revision}", Utils::Backtrace.clean(e)

View File

@ -409,7 +409,10 @@ module Homebrew
name += " (cask)" if ambiguous_casks.include?(formula_or_cask) name += " (cask)" if ambiguous_casks.include?(formula_or_cask)
onoe "#{Tty.blue}#{name}#{Tty.reset}: #{e}" onoe "#{Tty.blue}#{name}#{Tty.reset}: #{e}"
$stderr.puts Utils::Backtrace.clean(e) if debug && !e.is_a?(Livecheck::Error) if debug && !e.is_a?(Livecheck::Error)
require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e)
end
print_resources_info(resource_version_info, verbose:) if check_for_resources print_resources_info(resource_version_info, verbose:) if check_for_resources
nil nil
end end
@ -1056,7 +1059,10 @@ module Homebrew
status_hash(resource, "error", [e.to_s], verbose:) status_hash(resource, "error", [e.to_s], verbose:)
elsif !quiet elsif !quiet
onoe "#{Tty.blue}#{resource.name}#{Tty.reset}: #{e}" onoe "#{Tty.blue}#{resource.name}#{Tty.reset}: #{e}"
$stderr.puts Utils::Backtrace.clean(e) if debug && !e.is_a?(Livecheck::Error) if debug && !e.is_a?(Livecheck::Error)
require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e)
end
nil nil
end end
end end

View File

@ -226,7 +226,10 @@ class Migrator
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "The migration did not complete successfully." onoe "The migration did not complete successfully."
puts e puts e
puts Utils::Backtrace.clean(e) if debug? if debug?
require "utils/backtrace"
puts Utils::Backtrace.clean(e)
end
puts "Backing up..." puts "Backing up..."
ignore_interrupts { backup_oldname } ignore_interrupts { backup_oldname }
ensure ensure
@ -357,7 +360,10 @@ class Migrator
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "An unexpected error occurred during linking" onoe "An unexpected error occurred during linking"
puts e puts e
puts Utils::Backtrace.clean(e) if debug? if debug?
require "utils/backtrace"
puts Utils::Backtrace.clean(e)
end
ignore_interrupts { new_keg.unlink(verbose: verbose?) } ignore_interrupts { new_keg.unlink(verbose: verbose?) }
raise raise
end end

View File

@ -36,6 +36,7 @@ module Repology
data = JSON.parse(output) data = JSON.parse(output)
{ name => data } { name => data }
rescue => e rescue => e
require "utils/backtrace"
error_output = [errors, "#{e.class}: #{e}", Utils::Backtrace.clean(e)].compact error_output = [errors, "#{e.class}: #{e}", Utils::Backtrace.clean(e)].compact
if Homebrew::EnvConfig.developer? if Homebrew::EnvConfig.developer?
$stderr.puts(*error_output) $stderr.puts(*error_output)