Skip to content

cmd/search: resolve error with regex#21811

Merged
MikeMcQuaid merged 1 commit intomainfrom
search-resolve-error-with-regex
Mar 25, 2026
Merged

cmd/search: resolve error with regex#21811
MikeMcQuaid merged 1 commit intomainfrom
search-resolve-error-with-regex

Conversation

@samford
Copy link
Copy Markdown
Member

@samford samford commented Mar 23, 2026


  • 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 (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

When a regex string like /jq/ is provided to brew search, it can sometimes produce an error like "Error: /opt/homebrew/opt//jq/ is not a valid keg". So far I've only seen this with a very small number of installed formulae (I only stumbled upon this by chance). I'm not sure why some regexes trigger this and others don't but it traces back to the Formulary.path call in MissingFormula.deleted_reason. Either way, MissingFormula.reason shouldn't be called when the query value is a regex string, so this adds a guard to prevent it.

Copilot AI review requested due to automatic review settings March 23, 2026 19:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an error path in brew search when the user provides a regex query (e.g. /jq/), by preventing missing-formula lookup logic from running on regex-literal queries.

Changes:

  • Skip MissingFormula.reason when the search query is a /.../ regex literal.
  • Avoid triggering Formulary.path/keg-path resolution for regex queries when printing “missing formula” help.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/cmd/search.rb Outdated
Comment thread Library/Homebrew/cmd/search.rb
Copy link
Copy Markdown
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! Good once comments addressed.

Comment thread Library/Homebrew/cmd/search.rb Outdated
Comment thread Library/Homebrew/cmd/search.rb
@samford samford force-pushed the search-resolve-error-with-regex branch from 314a31b to 4f2320b Compare March 25, 2026 03:33
When a regex string like `/jq/` is provided to `brew search`, it can
sometimes produce an error like "Error: /opt/homebrew/opt//jq/ is not
a valid keg". So far I've only seen this with a very small number of
installed formulae (I only stumbled upon this by chance). I'm not
sure why some regexes trigger this and others don't but it traces
back to the `Formulary.path` call in `MissingFormula.deleted_reason`.
Either way, `MissingFormula.reason` shouldn't be called when the
`query` value is a regex string, so this adds a guard to prevent it.
@samford samford force-pushed the search-resolve-error-with-regex branch from 4f2320b to 368a773 Compare March 25, 2026 15:46
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit f5db81f Mar 25, 2026
41 checks passed
@MikeMcQuaid MikeMcQuaid deleted the search-resolve-error-with-regex branch March 25, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants