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

cask/info: send missing args after removing openstruct #18917

Merged
merged 2 commits into from
Dec 12, 2024

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?

This should fix #18915 and is an attempt to fix forward so we don't have to rollback #18847 since this seems like a minor issue.

This seems like it was a bug before the recent change to remove OpenStruct from Homebrew::CLI::Args but it was failing silently before. Now we pass the args to the Cask::Info.info method so that when they eventually reach the Utils::Analytics.output_analytics method they are present as expected.

Note that this error requires HOMEBREW_NO_ANALYTICS to not be set and --verbose to be passed along with brew info CASK.

Example error fragment:

$ set -e HOMEBREW_NO_ANALYTICS
$ brew info iterm2 --cask --verbose
==> iterm2: 3.5.10 (auto_updates)
https://iterm2.com/
Installed
/usr/local/Caskroom/iterm2/3.5.4 (91.7MB)
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/i/iterm2.rb
==> Name
iTerm2
==> Description
Terminal emulator as alternative to Apple's Terminal app
==> Artifacts
iTerm.app (App)
Error: undefined method `analytics?' for an instance of Homebrew::CLI::Args
/usr/local/Homebrew/Library/Homebrew/utils/analytics.rb:248:in `output_analytics'
/usr/local/Homebrew/Library/Homebrew/utils/analytics.rb:342:in `cask_output'
/usr/local/Homebrew/Library/Homebrew/cask/info.rb:39:in `info'
...

Expected output:

$ brew info iterm2 --cask --verbose
==> iterm2: 3.5.10 (auto_updates)
https://iterm2.com/
Installed
/usr/local/Caskroom/iterm2/3.5.4 (91.7MB)
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/i/iterm2.rb
==> Name
iTerm2
==> Description
Terminal emulator as alternative to Apple's Terminal app
==> Artifacts
iTerm.app (App)
==> Analytics
==> install (30 days)
Index | Name (with options)                                                                          |  Count |  Percent
-----:|----------------------------------------------------------------------------------------------|-------:|--------:
1     | iterm2                                                                                       | 27,977 |  100.00%
==> install (90 days)
Index | Name (with options)                                                                          |  Count |  Percent
-----:|----------------------------------------------------------------------------------------------|-------:|--------:
1     | iterm2                                                                                       | 75,134 |  100.00%
==> install (365 days)
Index | Name (with options)                                                                         |   Count |  Percent
-----:|---------------------------------------------------------------------------------------------|--------:|--------:
1     | iterm2                                                                                      | 287,267 |  100.00%

This seems like it was a bug before the recent change to remove
OpenStruct from `Homebrew::CLI::Args` but it was failing silently
before. Now we pass the args to the `Cask::Info.info` method so
that when they eventually reach the `Utils::Analytics.output_analytics`
method they are present as expected.

Example error fragment:

```console
$ set -e HOMEBREW_NO_ANALYTICS
$ brew info iterm2 --cask --verbose
==> iterm2: 3.5.10 (auto_updates)
https://iterm2.com/
Installed
/usr/local/Caskroom/iterm2/3.5.4 (91.7MB)
From: https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/i/iterm2.rb
==> Name
iTerm2
==> Description
Terminal emulator as alternative to Apple's Terminal app
==> Artifacts
iTerm.app (App)
Error: undefined method `analytics?' for an instance of Homebrew::CLI::Args
/usr/local/Homebrew/Library/Homebrew/utils/analytics.rb:248:in `output_analytics'
/usr/local/Homebrew/Library/Homebrew/utils/analytics.rb:342:in `cask_output'
/usr/local/Homebrew/Library/Homebrew/cask/info.rb:39:in `info'
```
@apainintheneck apainintheneck added the bug Reproducible Homebrew/brew bug label Dec 12, 2024
::Utils::Analytics.cask_output(cask, args: Homebrew::CLI::Args.new)
::Utils::Analytics.cask_output(cask, args:)
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 believe this was an existing bug that only came to light because of recent changes. It seems like by creating a new instance of the CLI args here that args.analytics? would always be falsey later on which doesn't seem to be the desired behavior. Now when the --analytics flag is set it will get passed to Utils::Analytics.cask_output the same way it already gets passed to Utils::Analytics.formula_output.

Copy link
Member

Choose a reason for hiding this comment

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

Nice work! We might want to add some guardrails around where/how Args can be instantiated 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO it's probably not necessary unless it's really simple to implement since I doubt that we'll ever run into the same problem again.

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.

Thanks @apainintheneck!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Dec 12, 2024
Merged via the queue into master with commit 9783ab0 Dec 12, 2024
28 checks passed
@MikeMcQuaid MikeMcQuaid deleted the send-args-to-cask-info branch December 12, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/brew bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

brew info reports "undefined method `analytics?'" on casks
3 participants