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

dev-cmd/unbottled: Fail nicely if HOMEBREW_NO_ANALYTICS is set #9312

Merged

Conversation

issyl0
Copy link
Member

@issyl0 issyl0 commented Nov 26, 2020

  • 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 tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

  • When testing brew unbottled this crashed because I, as a maintainer, have HOMEBREW_NO_ANALYTICS set on all my machines to avoid polluting the analytics with test installs.
❯ brew unbottled
==> Getting formulae...
==> Getting analytics data...
Error: undefined method `[]' for nil:NilClass
/usr/local/Homebrew/Library/Homebrew/dev-cmd/unbottled.rb:89:in `formulae_all_sort_installs_from_args'
/usr/local/Homebrew/Library/Homebrew/dev-cmd/unbottled.rb:49:in `unbottled'
/usr/local/Homebrew/Library/Homebrew/brew.rb:119:in `<main>'

@BrewTestBot
Copy link
Member

Review period will end on 2020-11-27 at 16:59:22 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Nov 26, 2020
@issyl0
Copy link
Member Author

issyl0 commented Nov 26, 2020

Wait... maybe this was a red herring. Maybe it crashed because I didn't specify a formula (I assumed that brew unbottled worked like brew find-not-bottled in Homebrew/linux-dev in that it surfaced everything without a bottle). Either way there's something wrong, it just might not be exactly this fix.

@issyl0
Copy link
Member Author

issyl0 commented Nov 26, 2020

Turns out it does work like I thought it does (so this fix is good), I just read too fast! brew unbottled with no formula args (which is valid) does work on this branch whereas it doesn't on master.

@MikeMcQuaid
Copy link
Member

I'd suggest instead checking for analytics.blank? in

analytics = Utils::Analytics.formulae_brew_sh_json("analytics/install/90d.json")

and doing something like

raise UsageError, 
  "default sort by analytics data requires `HOMEBREW_NO_GITHUB_API` and `HOMEBREW_NO_ANALYTICS` to be unset!"

because the current conditions won't quite catch all the cases where this can occur.

@issyl0 issyl0 force-pushed the unbottled-fail-nicely-if-HOMEBREW_NO_ANALYTICS branch from f1cd040 to 0dc8ada Compare November 26, 2020 19:36
@issyl0
Copy link
Member Author

issyl0 commented Nov 26, 2020

The review period works for better code! Thanks @MikeMcQuaid.

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.

👍🏻 to 🚢 once typo change and brew style are fixed.

Library/Homebrew/dev-cmd/unbottled.rb Outdated Show resolved Hide resolved
- When testing `brew unbottled <formula>` this crashed because I, as a
  maintainer, have `HOMEBREW_NO_ANALYTICS` set on all my machines to
  avoid polluting the analytics with test installs.

```
❯ brew unbottled
==> Getting formulae...
==> Getting analytics data...
Error: undefined method `[]' for nil:NilClass
/usr/local/Homebrew/Library/Homebrew/dev-cmd/unbottled.rb:89:in `formulae_all_sort_installs_from_args'
/usr/local/Homebrew/Library/Homebrew/dev-cmd/unbottled.rb:49:in `unbottled'
/usr/local/Homebrew/Library/Homebrew/brew.rb:119:in `<main>'
```
@issyl0 issyl0 force-pushed the unbottled-fail-nicely-if-HOMEBREW_NO_ANALYTICS branch from 0dc8ada to ca999a8 Compare November 26, 2020 21:22
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Nov 27, 2020
@BrewTestBot
Copy link
Member

Review period ended.

@issyl0 issyl0 merged commit f142714 into Homebrew:master Nov 27, 2020
@issyl0 issyl0 deleted the unbottled-fail-nicely-if-HOMEBREW_NO_ANALYTICS branch November 27, 2020 18:04
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Dec 28, 2020
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Dec 28, 2020
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

3 participants