fix(search): surface error exit codes and guard against false zero matches#2716
Open
guyoron1 wants to merge 1 commit into
Open
fix(search): surface error exit codes and guard against false zero matches#2716guyoron1 wants to merge 1 commit into
guyoron1 wants to merge 1 commit into
Conversation
…tches Two defensive improvements for rg/grep output handling: 1. When the search engine exits with code >= 2 (error) and stdout is empty, print an error indicator to stdout so agents in hook contexts can see it (stderr alone may not be surfaced by the hook pipeline). 2. When total_matches is 0 but the engine exited successfully (code 0) with non-empty output, fall through to passthrough instead of reporting "0 matches" — this catches cases where parse_match_line failed to parse the output format. Relates to rtk-ai#2563
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.
Summary
Two defensive improvements to the rg/grep search handler that address the root patterns behind #2563:
Surface error exit codes to stdout: When rg/grep exits with code >= 2 (error) and stdout is empty, print an error indicator to stdout. In hook contexts (Claude Code), stderr may not be surfaced to the agent — without stdout output, the agent sees silence and may misinterpret it as "no matches"
Guard against false "0 matches": When
total_matchesis 0 but the engine exited successfully (code 0) with non-empty output, fall through to passthrough instead of reporting "0 matches in 0 files". This catches edge cases whereparse_match_linefails to parse an unexpected output format — the raw output is preserved rather than silently replaced with a false zero countContext
Issue #2563 reported false "0 matches" with escaped regex patterns via the hook pipeline. The original issue was on rtk 0.42.1 which lacked a native search handler; the current native handler (added later) correctly passes patterns through. These changes add defensive guards so that if parsing ever fails partially, the handler falls back to passthrough rather than emitting misleading results.
Test plan
cargo clippy --all-targetspassescargo test --allpasses (all 11 search tests pass includinggrep_and_rg_use_their_own_regex_dialect)Relates to #2563