ripgrep causes Grep tool to fail in the presence of broken symlinks
Description
When a model calls the Grep tool, it will fail if the target directory, or any child of that directory, contains broken symlinks. This is directly caused by using the ripgrep --follow parameter (https://github.com/anomalyco/opencode/pull/7501).
Here is an example of what ripgrep is returning in this case:
[phelps@arch opencode]$ rg --follow Ripgrep.search
rg: ./subdir/broken: No such file or directory (os error 2)
packages/opencode/src/cli/cmd/debug/ripgrep.ts
79: const results = await Ripgrep.search({
packages/opencode/src/server/server.ts
1937: const result = await Ripgrep.search({
[phelps@arch opencode]$ echo $?
2
And opencode shows this as:
✱ Grep "GrepTool" in .
Error: ripgrep failed: rg: /home/phelps/opencode/subdir/broken: No such file or directory (os error 2)
Note the exit code of 2. This causes the Grep tool to return an error, and none of the content. It might make sense to only return an error if there isn't anything in stdout? However, then you'd end up stripping some potentially useful information that ripgrep could be reporting.
Here is the relevant section of the ripgrep man page:
• 2 exit status occurs when an error occurred. This is true for both
catastrophic errors (e.g., a regex syntax error) and for soft
errors (e.g., unable to read a file).
Plugins
No response
OpenCode version
1.1.18
Steps to reproduce
Create a broken symlink somewhere in your project and ask a model to grep for something in the root of the repo:
phelps@arch ~/opencode> mkdir subdir
phelps@arch ~/opencode> ln -s ../broken subdir/
Screenshot and/or share link
Short exchange where this resulted in an extra turn in which rg was invoked manually: https://opncd.ai/share/6djY8XRM
Operating System
Arch Linux
Terminal
foot