Skip to content

fix(ripgrep): handle broken symlinks gracefully in files() stream#24973

Open
aaronkyriesenbach wants to merge 1 commit into
anomalyco:devfrom
aaronkyriesenbach:fix/glob-broken-symlinks
Open

fix(ripgrep): handle broken symlinks gracefully in files() stream#24973
aaronkyriesenbach wants to merge 1 commit into
anomalyco:devfrom
aaronkyriesenbach:fix/glob-broken-symlinks

Conversation

@aaronkyriesenbach
Copy link
Copy Markdown

@aaronkyriesenbach aaronkyriesenbach commented Apr 29, 2026

Issue for this PR

Closes #24972

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The glob tool silently returns zero results when any broken symlink or permission-denied path exists in the search tree. This happens because Ripgrep.files() treats ripgrep exit code 2 as fatal — it discards all valid stdout output and fails the stream.

The search() function (used by the grep tool) already handles this correctly: it passes --no-messages to suppress stderr warnings and treats exit code 2 as non-fatal. files() was missed.

This PR brings files() in line with search():

  1. Adds --no-messages to filesArgs() so stderr warnings about broken symlinks don't pollute output.
  2. Treats exit code 2 as non-fatal in the files() stream so valid results already emitted to stdout are kept instead of discarded.

How did you verify your code works?

  • Added a test (files returns valid results despite broken symlinks) that creates a directory with a real file and a broken symlink, calls rg.files() with follow: true, and asserts the real file is returned.
  • All existing tests pass: 13 ripgrep tests, 2 glob tests, 4 grep tests.
  • Full monorepo typecheck passes (13/13 packages via bun turbo typecheck).
  • Confirmed the underlying behavior on a system with broken symlinks (pnpm store, paru cache, Firefox/Cider lock files): rg --files --follow returns the target file on stdout but exits with code 2, which the unpatched files() would treat as fatal.
  • Confirmed that running OpenCode locally with this fix finds files using a glob pattern that does not work with the latest release build.

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Ripgrep exits with code 2 when it encounters soft errors like broken
symlinks or permission-denied paths, even though valid results are still
written to stdout. The search() function already handled this, but
files() treated exit code 2 as fatal — discarding all results.

Add --no-messages to suppress stderr warnings in filesArgs() (matching
searchArgs) and treat exit code 2 as non-fatal in the files() stream.

This fixes the glob tool silently returning zero results when any broken
symlink exists in the search tree.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@aaronkyriesenbach aaronkyriesenbach marked this pull request as draft April 29, 2026 15:53
@aaronkyriesenbach aaronkyriesenbach marked this pull request as ready for review April 29, 2026 17:31
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.

Glob tool returns zero results when broken symlinks exist in the search tree

1 participant