Skip to content

fix(search): surface error exit codes and guard against false zero matches#2716

Open
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/search-rg-error-exit-code
Open

fix(search): surface error exit codes and guard against false zero matches#2716
guyoron1 wants to merge 1 commit into
rtk-ai:developfrom
guyoron1:fix/search-rg-error-exit-code

Conversation

@guyoron1

Copy link
Copy Markdown
Contributor

Summary

Two defensive improvements to the rg/grep search handler that address the root patterns behind #2563:

  1. 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"

  2. Guard against false "0 matches": 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 in 0 files". This catches edge cases where parse_match_line fails to parse an unexpected output format — the raw output is preserved rather than silently replaced with a false zero count

Context

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-targets passes
  • cargo test --all passes (all 11 search tests pass including grep_and_rg_use_their_own_regex_dialect)

Relates to #2563

…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
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.

1 participant