Skip to content

Commit

Permalink
Add utils/backtrace requires
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samford committed Jul 15, 2024
1 parent cb48a95 commit 11d6785
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
12 changes: 8 additions & 4 deletions Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@
Homebrew::Help.help cmd, remaining_args: args&.remaining, usage_error: e.message
rescue SystemExit => e
onoe "Kernel.exit" if args&.debug? && !e.success?
require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug")
if args&.debug? || ARGV.include?("--debug")
require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e)

Check warning on line 152 in Library/Homebrew/brew.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/brew.rb#L152

Added line #L152 was not covered by tests
end
raise
rescue Interrupt
$stderr.puts # seemingly a newline is typical
Expand Down Expand Up @@ -185,8 +187,10 @@
raise if e.message.empty?

onoe e
require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug")
if args&.debug? || ARGV.include?("--debug")
require "utils/backtrace"
$stderr.puts Utils::Backtrace.clean(e)

Check warning on line 192 in Library/Homebrew/brew.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/brew.rb#L192

Added line #L192 was not covered by tests
end

exit 1
rescue Exception => e # rubocop:disable Lint/RescueException
Expand Down
10 changes: 8 additions & 2 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def output_update_report
begin
reporter = Reporter.new(tap)
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
end
if reporter.updated?
Expand Down Expand Up @@ -624,7 +627,10 @@ def migrate_tap_migration
system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite"
end
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
next
end
Expand Down
18 changes: 17 additions & 1 deletion Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,12 @@ def link(keg)
ofail "An unexpected error occurred during the `brew link` step"
puts "The formula built, but is not symlinked into #{HOMEBREW_PREFIX}"
puts e
puts Utils::Backtrace.clean(e) if debug?

if debug?
require "utils/backtrace"
puts Utils::Backtrace.clean(e)

Check warning on line 1040 in Library/Homebrew/formula_installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_installer.rb#L1040

Added line #L1040 was not covered by tests
end

@show_summary_heading = true
ignore_interrupts do
keg.unlink
Expand Down Expand Up @@ -1080,6 +1085,8 @@ def install_service
rescue Exception => e # rubocop:disable Lint/RescueException
puts e
ofail "Failed to install service files"

require "utils/backtrace"

Check warning on line 1089 in Library/Homebrew/formula_installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_installer.rb#L1089

Added line #L1089 was not covered by tests
odebug e, Utils::Backtrace.clean(e)
end

Expand All @@ -1090,7 +1097,10 @@ def fix_dynamic_linkage(keg)
ofail "Failed to fix install linkage"
puts "The formula built, but you may encounter issues using it or linking other"
puts "formulae against it."

require "utils/backtrace"

Check warning on line 1101 in Library/Homebrew/formula_installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_installer.rb#L1101

Added line #L1101 was not covered by tests
odebug e, Utils::Backtrace.clean(e)

@show_summary_heading = true
end

Expand All @@ -1101,7 +1111,10 @@ def clean
rescue Exception => e # rubocop:disable Lint/RescueException
opoo "The cleaning step did not complete successfully"
puts "Still, the installation was successful, so we will link it into your prefix."

require "utils/backtrace"

Check warning on line 1115 in Library/Homebrew/formula_installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_installer.rb#L1115

Added line #L1115 was not covered by tests
odebug e, Utils::Backtrace.clean(e)

Homebrew.failed = true
@show_summary_heading = true
end
Expand Down Expand Up @@ -1171,7 +1184,10 @@ def post_install
opoo "The post-install step did not complete successfully"
puts "You can try again using:"
puts " brew postinstall #{formula.full_name}"

require "utils/backtrace"

Check warning on line 1188 in Library/Homebrew/formula_installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_installer.rb#L1188

Added line #L1188 was not covered by tests
odebug e, Utils::Backtrace.clean(e), always_display: Homebrew::EnvConfig.developer?

Homebrew.failed = true
@show_summary_heading = true
end
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/formula_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def formula_at_revision(revision, formula_relative_path = relative_path, &_block
nostdout { Formulary.from_contents(name, path, contents, ignore_errors: true) }
end
rescue *IGNORED_EXCEPTIONS => e
require "utils/backtrace"

Check warning on line 58 in Library/Homebrew/formula_versions.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_versions.rb#L58

Added line #L58 was not covered by tests

# We rescue these so that we can skip bad versions and
# continue walking the history
odebug "#{e} in #{name} at revision #{revision}", Utils::Backtrace.clean(e)
Expand Down
10 changes: 8 additions & 2 deletions Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ def run_checks(
name += " (cask)" if ambiguous_casks.include?(formula_or_cask)

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)

Check warning on line 414 in Library/Homebrew/livecheck/livecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/livecheck/livecheck.rb#L414

Added line #L414 was not covered by tests
end
print_resources_info(resource_version_info, verbose:) if check_for_resources
nil
end
Expand Down Expand Up @@ -1056,7 +1059,10 @@ def resource_version(
status_hash(resource, "error", [e.to_s], verbose:)
elsif !quiet
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)

Check warning on line 1064 in Library/Homebrew/livecheck/livecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/livecheck/livecheck.rb#L1064

Added line #L1064 was not covered by tests
end
nil
end
end
Expand Down
10 changes: 8 additions & 2 deletions Library/Homebrew/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ def migrate
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "The migration did not complete successfully."
puts e
puts Utils::Backtrace.clean(e) if debug?
if debug?
require "utils/backtrace"
puts Utils::Backtrace.clean(e)

Check warning on line 231 in Library/Homebrew/migrator.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/migrator.rb#L231

Added line #L231 was not covered by tests
end
puts "Backing up..."
ignore_interrupts { backup_oldname }
ensure
Expand Down Expand Up @@ -357,7 +360,10 @@ def link_newname
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "An unexpected error occurred during linking"
puts e
puts Utils::Backtrace.clean(e) if debug?
if debug?
require "utils/backtrace"
puts Utils::Backtrace.clean(e)

Check warning on line 365 in Library/Homebrew/migrator.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/migrator.rb#L365

Added line #L365 was not covered by tests
end
ignore_interrupts { new_keg.unlink(verbose: verbose?) }
raise
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/utils/repology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def self.single_package_query(name, repository:)
data = JSON.parse(output)
{ name => data }
rescue => e
require "utils/backtrace"

Check warning on line 39 in Library/Homebrew/utils/repology.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/repology.rb#L39

Added line #L39 was not covered by tests
error_output = [errors, "#{e.class}: #{e}", Utils::Backtrace.clean(e)].compact
if Homebrew::EnvConfig.developer?
$stderr.puts(*error_output)
Expand Down

0 comments on commit 11d6785

Please sign in to comment.