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

cli/parser: rescue formula specification errors #16129

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?

Closes #16123

This came up recently where an outdated formula definition caused the program to crash with an ambiguous message when a user wanted to upgrade a cask instead. Catching these errors allows them to get handled later on improving error messages and defaults. Now if the only formula with the given name is invalid it will default to using the cask unless --formula is specified.

After changes:

$ brew install -n vagrant
Error: Failed to load formula: vagrant
formulae require at least a URL
Warning: Treating vagrant as a cask.
==> Would install 1 cask:
vagrant
$ brew install -n vagrant --formula
Error: formulae require at least a URL
Warning: Removed Sorbet lines from backtrace!
Rerun with --verbose to see the original backtrace
/usr/local/Homebrew/Library/Homebrew/formula.rb:306:in `determine_active_spec'
/usr/local/Homebrew/Library/Homebrew/formula.rb:237:in `initialize'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:494:in `new'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:494:in `get_formula'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:771:in `factory'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:126:in `block in load_formula_or_cask'
/usr/local/Homebrew/Library/Homebrew/api.rb:197:in `with_no_api_env_if_needed'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:118:in `load_formula_or_cask'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:83:in `block in to_formulae_and_casks'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:81:in `each'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:81:in `flat_map'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:81:in `to_formulae_and_casks'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:195:in `install'
/usr/local/Homebrew/Library/Homebrew/brew.rb:86:in `<main>'

This came up recently where an outdated formula definition
caused the program to crash with an ambiguous message when
a user wanted to upgrade a cask instead. Catching these errors
allows them to get handled later on improving error messages
and defaults. Now if the only formula with the given name is
invalid it will default to using the cask unless --formula is
specified.

- Homebrew#16123
@Bo98
Copy link
Member

Bo98 commented Oct 22, 2023

Eventually upstream will hopefully fix the formula specification, but then the user will get depends_on :linux issues so would still be nice to have better prioritisation for brew upgrade at some point.

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 again @apainintheneck!

@MikeMcQuaid MikeMcQuaid merged commit 35746e0 into Homebrew:master Oct 22, 2023
27 checks passed
@apainintheneck
Copy link
Contributor Author

@Bo98 What do you mean by better prioritization? I guess we could try to resolve name conflicts by defaulting to the installed package if only one package with that name is installed for brew upgrade. Is that what you had in mind?

@ONLi54tNDa

This comment has been minimized.

@Bo98
Copy link
Member

Bo98 commented Oct 26, 2023

Yeah. Feels more secure since it would prevent a tap from hijacking an existing install without the user really noticing sometimes.

@github-actions github-actions bot added the outdated PR was locked due to age label Nov 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2023
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.

Error: formulae require at least a URL after upgrading MacOS to 14.0
4 participants