Skip to content

Comments

fix: propagate rg exit code in rtk grep for CLI parity#227

Merged
pszymkowiak merged 1 commit intortk-ai:masterfrom
polaminggkub-debug:fix/grep-exit-code-parity
Feb 20, 2026
Merged

fix: propagate rg exit code in rtk grep for CLI parity#227
pszymkowiak merged 1 commit intortk-ai:masterfrom
polaminggkub-debug:fix/grep-exit-code-parity

Conversation

@polaminggkub-debug
Copy link
Contributor

Summary

  • rtk grep returned exit 0 for all failure modes where rg returns non-zero
  • Now propagates exit codes: 1 (no match), 2 (error — bad regex, missing file)
  • Surfaces rg stderr on error so users see why it failed

Before / After

Scenario Before After rg native
No match exit 0 exit 1 exit 1
Bad regex ([) exit 0 exit 2 exit 2
Missing file exit 0 exit 2 exit 2
Match found exit 0 exit 0 exit 0

Test plan

  • rtk grep "zzz" file → exit 1 (no match)
  • rtk grep "[" file → exit 2 + stderr error message
  • rtk grep "alpha" /nonexistent → exit 2 + stderr error message
  • rtk grep "alpha" file → exit 0 (match found, unchanged)
  • cargo test grep_cmd — 8 tests pass
  • cargo test --all — 412 pass, 0 fail

Fixes #162

🤖 Generated with Claude Code

rtk grep previously returned exit 0 for all failure modes (no match,
invalid regex, missing file) where rg returns non-zero. This broke
shell workflows relying on exit code semantics.

Now propagates rg exit codes: 1 (no match), 2 (error) and surfaces
stderr for error cases so users see why the command failed.

Fixes rtk-ai#162

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Collaborator

LGTM — tested locally, all good.

  • 412 tests pass, no conflicts with master
  • 82/83 smoke tests pass (1 false positive: test script hardcodes expected test count)
  • Exit codes verified manually:
    • Match found → exit 0 ✅
    • No match → exit 1 ✅ (was 0)
    • Bad regex → exit 2 + stderr ✅ (was 0)
    • Missing file → exit 2 + stderr ✅ (was 0)
  • No regression on any other command (ls, git, gh, find, grep, cargo, curl, etc.)

Fixes #162. Ready to merge.

@pszymkowiak pszymkowiak merged commit f1be885 into rtk-ai:master Feb 20, 2026
2 of 3 checks passed
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.

bug: rtk grep exit-code parity differs from rg (always 0 for key failure modes)

2 participants