Mintplex-Labs/anything-llm · error
ripgrep exited with code ${result.status}
Error message
ripgrep exited with code ${result.status} What it means
Thrown by searchFilesWithRipgrepGlob when the spawned ripgrep process exits with a status greater than 1 while listing files by glob. Exit code 1 deliberately means 'no matches' and is not an error; codes above 1 indicate ripgrep failed (bad glob syntax, unreadable path, missing binary). The error message prefers ripgrep's stderr when present, otherwise reports the numeric exit code.
Source
Thrown at server/utils/agents/aibitat/plugins/filesystem/search-files.js:292
const args = [
"--files", // List files instead of searching content
"--no-ignore", // Search all files, even those in .gitignore
];
// Add glob patterns (ripgrep uses --glob for filtering --files output)
for (const pattern of patterns) args.push("--glob", pattern);
for (const exclude of excludePatterns) args.push("--glob", `!${exclude}`);
// The "--" prevents searchPath from being parsed as an option if it starts with "-"
// (defense against argument injection attacks)
args.push("--", searchPath);
const result = spawnSync(rgPath, args, {
encoding: "utf-8",
maxBuffer: 10 * 1024 * 1024,
});
if (result.status > 1) {
throw new Error(
result.stderr || `ripgrep exited with code ${result.status}`
);
}
// unique files
const files = new Set();
if (!result.stdout) return { files: Array.from(files), method: "ripgrep" };
const lines = result.stdout.trim().split("\n").filter(Boolean);
for (const line of lines) {
files.add(line);
if (files.size >= maxResults) break;
}
return { files: Array.from(files), method: "ripgrep" };
}
/**View on GitHub (pinned to 3aec848f28)
Solutions
- Read the message: if it is stderr text, it names the exact bad argument (usually a --glob value); fix or simplify that glob.
- Confirm searchPath exists and is readable: ls -la <searchPath> under the same user the server runs as.
- Sanity-check the binary: run "$(node -e \"print require('@vscode/ripgrep').rgPath\")" --version; reinstall @vscode/ripgrep if it fails.
- Remember status 1 with empty output is a normal 'no files matched', not this error — do not chase it.
Example fix
// before
search_files({ path: "src", include: "src/{*.js" }) // unbalanced brace -> rg exit 2
// after
search_files({ path: "src", include: "*.js" }) Defensive patterns
Strategy: try-catch
Validate before calling
const fs = require("fs");
function validateGlobSearch(searchPath, patterns) {
if (!fs.existsSync(searchPath) || !fs.statSync(searchPath).isDirectory()) {
throw new Error(`searchPath is not a readable directory: ${searchPath}`);
}
for (const g of patterns) {
if (typeof g !== "string" || /[{}]{1}/.test(g.replace(/\\[{}]/g, "")) === false && (g.match(/{/g)?.length !== g.match(/}/g)?.length)) {
throw new Error(`possibly unbalanced glob: ${g}`);
}
}
} Try / catch
try {
const res = searchFilesWithRipgrepGlob({ searchPath, patterns, excludePatterns });
} catch (e) {
// e.message is ripgrep stderr when present — it names the offending --glob or path
if (/unrecognized|invalid/i.test(e.message)) fixGlobFromMessage(e.message);
else if (/exit code/.test(e.message)) checkRgBinary();
throw e;
} Prevention
- Validate globs client-side: balanced braces, no NUL bytes, plain wildcards preferred.
- Confirm searchPath exists under the sandbox before searching.
- Treat exit 1 (or empty stdout) as 'no matches', not failure.
When it happens
Trigger: Passing an invalid glob to --glob (e.g. unbalanced braces like "src/{*.js"); searchPath does not exist or is unreadable by the rg process; the rg binary downloaded by @vscode/ripgrep is missing/corrupt so the spawn errors out; glob containing characters rg treats as invalid UTF-8.
Common situations: LLM agent fabricates a malformed glob; searchPath typos ('./srcc'); container runs as a non-root user that cannot traverse the directory; @vscode/ripgrep postinstall silently failed so rgPath points nowhere.
Related errors
- @vscode/ripgrep not installed
- search pattern must not start with '-'
- QEMU directory not found: ${dir}\nContents of ${parent}: ${c
- ${text} Command exited with code ${realExitCode}
- Cannot copy symbolic link: ${source}. Symlinks are not allow
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/bee33d6c2830bf5a.
Report an issue: GitHub.