cmd/search: resolve error with regex#21811
Merged
MikeMcQuaid merged 1 commit intomainfrom Mar 25, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.reasonwhen 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.
MikeMcQuaid
approved these changes
Mar 23, 2026
Member
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks! Good once comments addressed.
314a31b to
4f2320b
Compare
carlocab
approved these changes
Mar 25, 2026
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.
4f2320b to
368a773
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
brew lgtm(style, typechecking and tests) with your changes locally?When a regex string like
/jq/is provided tobrew 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 theFormulary.pathcall inMissingFormula.deleted_reason. Either way,MissingFormula.reasonshouldn't be called when thequeryvalue is a regex string, so this adds a guard to prevent it.