Skip to content

Commit

Permalink
cmd/doctor: Add --ignore-warnings
Browse files Browse the repository at this point in the history
When `brew doctor` is run, `brew` exits with a non-zero status if any
warnings or errors are encountered. However, this groups warnings and
errors together, but (as the output notes) warnings can be innocuous:

> Please note that these warnings are just used to help the Homebrew
> maintainers with debugging if you file an issue. If everything you use
> Homebrew for is working fine: please don't worry or file an issue;
> just ignore this. Thanks!

The `--ignore-warnings` switch makes it possible for automated tools
interacting with Homebrew to distinguish between warnings and hard
errors.

```
$ brew doctor --ignore-warnings
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed casks are deprecated or disabled.
You should find replacements for the following casks:
  graphql-playground
$ echo "$?"
0
```

Hard errors will still cause a non-zero exit status:

```
$ brew doctor --ignore-warnings
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: gettext files detected at a system prefix.
These files can cause compilation and link failures, especially if they
are compiled with improper architectures. Consider removing these files:
  /opt/homebrew/lib/libgettextlib.dylib
  /opt/homebrew/lib/libintl.dylib
  /opt/homebrew/include/libintl.h
Error: unknown or unsupported macOS version: :dunno
$ echo "$?"
1
```
  • Loading branch information
9999years committed Jul 25, 2024
1 parent 759abe5 commit ab56cff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Library/Homebrew/cmd/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Doctor < AbstractCommand
switch "-D", "--audit-debug",
description: "Enable debugging and profiling of audit methods."

switch "--ignore-warnings",
description: "Only exit with a non-zero status if errors are " \
"encountered. Warnings are still displayed but will " \
"not cause the command to fail."

named_args :diagnostic_check
end

Expand All @@ -48,7 +53,7 @@ def run
methods = args.named
end

first_warning = T.let(true, T::Boolean)
seen_warning = T.let(false, T::Boolean)
methods.each do |method|
$stderr.puts Formatter.headline("Checking #{method}", color: :magenta) if args.debug?
unless checks.respond_to?(method)
Expand All @@ -59,7 +64,7 @@ def run
out = checks.send(method)
next if out.blank?

if first_warning
unless seen_warning
$stderr.puts <<~EOS
#{Tty.bold}Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
Expand All @@ -69,11 +74,11 @@ def run

$stderr.puts
opoo out
Homebrew.failed = true
first_warning = false
Homebrew.failed = true unless args.ignore_warnings?
seen_warning = true
end

puts "Your system is ready to brew." if !Homebrew.failed? && !args.quiet?
puts "Your system is ready to brew." if !Homebrew.failed? && !seen_warning && !args.quiet?
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/doctor.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab56cff

Please sign in to comment.