agentscope-ai/agentscope · error · RuntimeError
ripgrep error (code {result.exit_code}): {error_msg}
Error message
ripgrep error (code {result.exit_code}): {error_msg} What it means
The ripgrep subprocess exited with a code other than 0 (matches) or 1 (no matches) — e.g. 2 for usage/IO errors — and stderr is surfaced in a RuntimeError.
Source
Thrown at src/agentscope/tool/_builtin/_grep.py:309
result = await self._backend.exec_shell(
command,
timeout=float(timeout),
)
if result.exit_code == -1 and result.stderr == b"timed out":
raise RipgrepTimeoutError(
f"Ripgrep search timed out after {timeout} seconds. "
"Try searching a more specific path or pattern.",
[],
)
# returncode 0 = matches found, 1 = no matches
if result.exit_code not in (0, 1):
error_msg = result.stderr.decode(
"utf-8",
errors="ignore",
).strip()
raise RuntimeError(
f"ripgrep error (code {result.exit_code}): {error_msg}",
)
raw = result.stdout.decode("utf-8", errors="ignore")
lines = [
line.rstrip("\r") for line in raw.split("\n") if line.rstrip("\r")
]
return lines
async def call( # type: ignore[override]
self,
pattern: str,
path: str | None = None,
output_mode: Literal[
"content",
"files_with_matches",
"count",View on GitHub (pinned to e90f1c7592)
Solutions
- Test the regex with `rg --pcre2 'pattern' testfile` or python re first
- Verify the path exists and is readable
- Ensure ripgrep is installed and on PATH (command -v rg)
- Catch RuntimeError and feed stderr back for pattern correction
Example fix
# before
await grep(pattern='foo(', path='src')
# after
await grep(pattern='foo\(', path='src') Defensive patterns
Strategy: try-catch
Validate before calling
import re
try: re.compile(pattern)
except re.error: raise ValueError('invalid regex') Type guard
def valid_regex(p: str) -> bool:
try: re.compile(p); return True
except re.error: return False Try / catch
try:
res = await grep(pattern=pat, path=path)
except RuntimeError as e:
if 'ripgrep error' in str(e): logger.warning('bad pattern/path: %s', e)
raise Prevention
- Compile-check regexes before executing search tools
- Verify rg is installed (command -v rg) and paths are readable
- Feed stderr back to the model so it can fix the pattern
When it happens
Trigger: Invalid regex pattern (unbalanced parenthesis), nonexistent path, permission-denied directory, or missing rg binary producing a nonzero shell exit.
Common situations: LLM-generated regex that is syntactically invalid; searching paths the process can't read; rg not installed so the shell returns 127.
Related errors
- Ripgrep search timed out after {timeout} seconds. Try search
- {self.__class__.__name__} does not implement call
- {type(self).__name__} must be called with keyword arguments
- Invalid input_schema: {self.tool.input_schema}.
- The field `{key}` already exists in the original function sc
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/a47f4a0f4eac732c.
Report an issue: GitHub.