{"record":{"id":"bee33d6c2830bf5a","repo":"Mintplex-Labs/anything-llm","slug":"ripgrep-exited-with-code-result-status","errorCode":null,"errorMessage":"ripgrep exited with code ${result.status}","messagePattern":"ripgrep exited with code (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/plugins/filesystem/search-files.js","lineNumber":292,"sourceCode":"  const args = [\n    \"--files\", // List files instead of searching content\n    \"--no-ignore\", // Search all files, even those in .gitignore\n  ];\n\n  // Add glob patterns (ripgrep uses --glob for filtering --files output)\n  for (const pattern of patterns) args.push(\"--glob\", pattern);\n  for (const exclude of excludePatterns) args.push(\"--glob\", `!${exclude}`);\n\n  // The \"--\" prevents searchPath from being parsed as an option if it starts with \"-\"\n  // (defense against argument injection attacks)\n  args.push(\"--\", searchPath);\n  const result = spawnSync(rgPath, args, {\n    encoding: \"utf-8\",\n    maxBuffer: 10 * 1024 * 1024,\n  });\n\n  if (result.status > 1) {\n    throw new Error(\n      result.stderr || `ripgrep exited with code ${result.status}`\n    );\n  }\n\n  // unique files\n  const files = new Set();\n  if (!result.stdout) return { files: Array.from(files), method: \"ripgrep\" };\n\n  const lines = result.stdout.trim().split(\"\\n\").filter(Boolean);\n  for (const line of lines) {\n    files.add(line);\n    if (files.size >= maxResults) break;\n  }\n\n  return { files: Array.from(files), method: \"ripgrep\" };\n}\n\n/**","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/agents/aibitat/plugins/filesystem/search-files.js#L274-L310","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nsearch_files({ path: \"src\", include: \"src/{*.js\" })  // unbalanced brace -> rg exit 2\n\n// after\nsearch_files({ path: \"src\", include: \"*.js\" })","handlingStrategy":"try-catch","validationCode":"const fs = require(\"fs\");\nfunction validateGlobSearch(searchPath, patterns) {\n  if (!fs.existsSync(searchPath) || !fs.statSync(searchPath).isDirectory()) {\n    throw new Error(`searchPath is not a readable directory: ${searchPath}`);\n  }\n  for (const g of patterns) {\n    if (typeof g !== \"string\" || /[{}]{1}/.test(g.replace(/\\\\[{}]/g, \"\")) === false && (g.match(/{/g)?.length !== g.match(/}/g)?.length)) {\n      throw new Error(`possibly unbalanced glob: ${g}`);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = searchFilesWithRipgrepGlob({ searchPath, patterns, excludePatterns });\n} catch (e) {\n  // e.message is ripgrep stderr when present — it names the offending --glob or path\n  if (/unrecognized|invalid/i.test(e.message)) fixGlobFromMessage(e.message);\n  else if (/exit code/.test(e.message)) checkRgBinary();\n  throw e;\n}","preventionTips":["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."],"tags":["filesystem","ripgrep","subprocess","glob","exit-code"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}