Skip to content

Commit

Permalink
brew.rb: improve error message for miscased commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Nov 4, 2024
1 parent d0e438c commit 9fd678c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@
end

if internal_cmd || Commands.external_ruby_v2_cmd_path(cmd)
# All internal commands are downcased
# Since APFS is case-insensitive by default, Ruby will load the command file
# if user passes it mixed-case, but here invoking it will fail.
cmd = T.must(cmd).downcase
cmd = T.must(cmd)
cmd_class = Homebrew::AbstractCommand.command(cmd)
Homebrew.running_command = cmd
if cmd_class
Expand All @@ -96,7 +93,14 @@
Utils::Analytics.report_command_run(command_instance)
command_instance.run
else
Homebrew.public_send Commands.method_name(cmd)
begin
Homebrew.public_send Commands.method_name(cmd)
rescue NoMethodError => e
case_error = "undefined method `#{cmd.downcase}' for module Homebrew"

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/brew.rb#L99

Added line #L99 was not covered by tests
odie "Unknown command: brew #{cmd}" if e.message == case_error

raise

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

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/brew.rb#L102

Added line #L102 was not covered by tests
end
end
elsif (path = Commands.external_ruby_cmd_path(cmd))
Homebrew.running_command = cmd
Expand Down

0 comments on commit 9fd678c

Please sign in to comment.