Skip to content

Commit

Permalink
Merge pull request #17003 from Homebrew/more_do_not_report_issue
Browse files Browse the repository at this point in the history
brew.rb: tell more people to not report issues.
  • Loading branch information
MikeMcQuaid authored Apr 3, 2024
2 parents 2de8eee + 21d99c5 commit ce5887a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
46 changes: 24 additions & 22 deletions Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@
Utils::Analytics.report_build_error(e)
e.dump(verbose: args&.verbose?)

if e.formula.head? || e.formula.deprecated? || e.formula.disabled?
if OS.unsupported_configuration?
$stderr.puts "#{Tty.bold}Do not report this issue: you are running in an unsupported configuration.#{Tty.reset}"
elsif e.formula.head? || e.formula.deprecated? || e.formula.disabled?
reason = if e.formula.head?
"was built from an unstable upstream --HEAD"
elsif e.formula.deprecated?
Expand All @@ -166,35 +168,35 @@
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.
EOS

end

exit 1
rescue RuntimeError, SystemCallError => e
raise if e.message.empty?
rescue Exception => e # rubocop:disable Lint/RescueException
runtime_or_system_call_error = e.is_a?(RuntimeError) || e.is_a?(SystemCallError)
raise if runtime_or_system_call_error && e.message.empty?

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

exit 1
rescue MethodDeprecatedError => e
onoe e
if e.issues_url
$stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core):"
$stderr.puts " #{Formatter.url(e.issues_url)}"
method_deprecated_error = e.is_a?(MethodDeprecatedError)
runtime_or_system_call_or_method_deprecated_error = runtime_or_system_call_error || method_deprecated_error
if args&.debug? || ARGV.include?("--debug") || !runtime_or_system_call_or_method_deprecated_error
$stderr.puts Utils::Backtrace.clean(e)
end
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug")
exit 1
rescue Exception => e # rubocop:disable Lint/RescueException
onoe e
if internal_cmd && !OS.unsupported_configuration?
if Homebrew::EnvConfig.no_auto_update?
$stderr.puts "#{Tty.bold}Do not report this issue until you've run `brew update` and tried again.#{Tty.reset}"
else
$stderr.puts "#{Tty.bold}Please report this issue:#{Tty.reset}"
$stderr.puts " #{Formatter.url(OS::ISSUES_URL)}"
end

if OS.unsupported_configuration?
$stderr.puts "#{Tty.bold}Do not report this issue: you are running in an unsupported configuration.#{Tty.reset}"
elsif Homebrew::EnvConfig.no_auto_update?
$stderr.puts "#{Tty.bold}You have disabled automatic updates.#{Tty.reset}"
$stderr.puts "#{Tty.bold}Do not report this issue until you've run `brew update` and tried again.#{Tty.reset}"
elsif (issues_url = (method_deprecated_error && e.issues_url) || Utils::Backtrace.tap_error_url(e))
$stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core):"
$stderr.puts " #{Formatter.url(issues_url)}"
elsif internal_cmd
$stderr.puts "#{Tty.bold}Please report this issue:#{Tty.reset}"
$stderr.puts " #{Formatter.url(OS::ISSUES_URL)}"
end
$stderr.puts Utils::Backtrace.clean(e)

exit 1
else
exit 1 if Homebrew.failed?
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ module EnvConfig
},
HOMEBREW_NO_AUTO_UPDATE: {
description: "If set, do not automatically update before running some commands, e.g. " \
"`brew install`, `brew upgrade` and `brew tap`. Alternatively, " \
"run this less often by setting `HOMEBREW_AUTO_UPDATE_SECS` to a value higher than the default.",
"`brew install`, `brew upgrade` and `brew tap`. Preferably, " \
"run this less often by setting `HOMEBREW_AUTO_UPDATE_SECS` to a value higher than the " \
"default. Note that setting this and e.g. tapping new taps may result in a broken " \
"configuration. Please ensure you always run `brew update` before reporting any issues.",
boolean: true,
},
HOMEBREW_NO_BOOTSNAP: {
Expand Down
16 changes: 16 additions & 0 deletions Library/Homebrew/utils/backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def self.clean(error)
.tap { |new_backtrace| print_backtrace_message if old_backtrace_length > new_backtrace.length }
end

sig { returns(String) }
def self.sorbet_runtime_path
@sorbet_runtime_path ||= "#{Gem.paths.home}/gems/sorbet-runtime"
end

sig { void }
def self.print_backtrace_message
return if @print_backtrace_message

Expand All @@ -32,5 +34,19 @@ def self.print_backtrace_message

@print_backtrace_message = true
end

sig { params(error: Exception).returns(T.nilable(String)) }
def self.tap_error_url(error)
backtrace = error.backtrace
return if backtrace.blank?

backtrace.each do |line|
if (tap = line.match(%r{/Library/Taps/([^/]+/[^/]+)/}))
return "https://github.com/#{tap[1]}/issues/new"
end
end

nil
end
end
end
7 changes: 5 additions & 2 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3740,8 +3740,11 @@ command execution e.g. `$(cat file)`.
`HOMEBREW_NO_AUTO_UPDATE`

: If set, do not automatically update before running some commands, e.g. `brew
install`, `brew upgrade` and `brew tap`. Alternatively, run this less often by
setting `HOMEBREW_AUTO_UPDATE_SECS` to a value higher than the default.
install`, `brew upgrade` and `brew tap`. Preferably, run this less often by
setting `HOMEBREW_AUTO_UPDATE_SECS` to a value higher than the default. Note
that setting this and e.g. tapping new taps may result in a broken
configuration. Please ensure you always run `brew update` before reporting any
issues.

`HOMEBREW_NO_BOOTSNAP`

Expand Down
4 changes: 2 additions & 2 deletions manpages/brew.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" generated by kramdown
.TH "BREW" "1" "March 2024" "Homebrew"
.TH "BREW" "1" "April 2024" "Homebrew"
.SH NAME
brew \- The Missing Package Manager for macOS (or Linux)
.SH "SYNOPSIS"
Expand Down Expand Up @@ -2445,7 +2445,7 @@ If set, do not send analytics\. Google Analytics were destroyed\. For more infor
.UE
.TP
\fBHOMEBREW_NO_AUTO_UPDATE\fP
If set, do not automatically update before running some commands, e\.g\. \fBbrew install\fP, \fBbrew upgrade\fP and \fBbrew tap\fP\&\. Alternatively, run this less often by setting \fBHOMEBREW_AUTO_UPDATE_SECS\fP to a value higher than the default\.
If set, do not automatically update before running some commands, e\.g\. \fBbrew install\fP, \fBbrew upgrade\fP and \fBbrew tap\fP\&\. Preferably, run this less often by setting \fBHOMEBREW_AUTO_UPDATE_SECS\fP to a value higher than the default\. Note that setting this and e\.g\. tapping new taps may result in a broken configuration\. Please ensure you always run \fBbrew update\fP before reporting any issues\.
.TP
\fBHOMEBREW_NO_BOOTSNAP\fP
If set, do not use Bootsnap to speed up repeated \fBbrew\fP calls\.
Expand Down

0 comments on commit ce5887a

Please sign in to comment.