Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/prof: improve error messages #14652

Merged
merged 1 commit into from Feb 17, 2023

Conversation

apainintheneck
Copy link
Contributor

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Small changes to provide better errors when using brew prof.

  1. Provide an error message when the command is unknown.
  2. Suggest running the command again with -- if there is an invalid option which might have been meant for a subcommand.

Before

/u/l/Homebrew (master|✔) $ brew prof updat
Error: undefined method `extname' for nil:NilClass
/usr/local/Homebrew/Library/Homebrew/dev-cmd/prof.rb:30:in `prof'
/usr/local/Homebrew/Library/Homebrew/brew.rb:93:in `<main>'
/u/l/Homebrew (master|✔) [1]$ brew prof list -r
Usage: brew prof [--stackprof] command [...]

Run Homebrew with a Ruby profiler. For example, brew prof readall.

      --stackprof                  Use stackprof instead of ruby-prof (the
                                   default).
  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -v, --verbose                    Make some output more verbose.
  -h, --help                       Show this message.
Error: invalid option: -r

After

/u/l/Homebrew (improve-prof-errors|✔) $ brew prof updat
Usage: brew prof [--stackprof] command [...]

Run Homebrew with a Ruby profiler. For example, brew prof readall.

      --stackprof                  Use stackprof instead of ruby-prof (the
                                   default).
  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -v, --verbose                    Make some output more verbose.
  -h, --help                       Show this message.

Error: Invalid usage: `updat` is an unknown command!
/u/l/Homebrew (improve-prof-errors|✔) [1]$ brew prof list -r
Usage: brew prof [--stackprof] command [...]

Run Homebrew with a Ruby profiler. For example, brew prof readall.

      --stackprof                  Use stackprof instead of ruby-prof (the
                                   default).
  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -v, --verbose                    Make some output more verbose.
  -h, --help                       Show this message.
Error: invalid option: -r
Try `brew prof -- list -r` instead.

@BrewTestBot
Copy link
Member

Review period will end on 2023-02-17 at 02:28:36 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Feb 16, 2023
Copy link
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! One suggestion (that probably violates brew style so may want to do manually).

when ".rb"
# expected file extension so we do nothing
when ".sh"
raise UsageError, "`#{cmd}` is a Bash command!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise UsageError, "`#{cmd}` is a Bash command!"
raise UsageError, "As `#{cmd}` is a Bash command it cannot be profiled with `brew prof`! Try `hyperfine` for benchmarking instead."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/u/l/Homebrew (improve-prof-errors|✚1) [1]$ brew prof --version
Usage: brew prof [--stackprof] command [...]

Run Homebrew with a Ruby profiler. For example, brew prof readall.

      --stackprof                  Use stackprof instead of ruby-prof (the
                                   default).
  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -v, --verbose                    Make some output more verbose.
  -h, --help                       Show this message.

Error: Invalid usage: `--version` is a Bash command!
Try `hyperfine` for benchmarking instead.

Wary of the 80 character limit I opted for this instead.

- Provide an error message when the command is unknown.
- Suggest running the command again with `--` if there
  is an invalid option which might have been meant for
  a subcommand.
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Feb 17, 2023
@BrewTestBot
Copy link
Member

Review period ended.

@apainintheneck apainintheneck merged commit 8ff2e29 into Homebrew:master Feb 17, 2023
@github-actions github-actions bot added the outdated PR was locked due to age label Mar 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2023
@apainintheneck apainintheneck deleted the improve-prof-errors branch March 24, 2023 03:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants