From 084a6d2d4380abd3894058fff5829e4a7e2e5c5e Mon Sep 17 00:00:00 2001 From: "sentry[bot]" <39604003+sentry[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 22:44:42 +0000 Subject: [PATCH] fix(grep): Handle ripgrep literal newline regex error --- packages/junior/src/chat/tools/sandbox/grep.ts | 2 +- .../unit/tools/sandbox/file-tools.test.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/junior/src/chat/tools/sandbox/grep.ts b/packages/junior/src/chat/tools/sandbox/grep.ts index 1f32223249..0773708c94 100644 --- a/packages/junior/src/chat/tools/sandbox/grep.ts +++ b/packages/junior/src/chat/tools/sandbox/grep.ts @@ -334,7 +334,7 @@ async function grepFilesWithRipgrep(params: { cause: new Error(detail), }); } - if (/regex parse error|error parsing regex/i.test(detail)) { + if (/regex parse error|error parsing regex|is not allowed in a regex/i.test(detail)) { throw new ToolInputError(`Invalid regex pattern: ${params.pattern}`, { cause: new Error(detail), }); diff --git a/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts b/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts index cf65c1f4e5..988662413e 100644 --- a/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts +++ b/packages/junior/tests/unit/tools/sandbox/file-tools.test.ts @@ -416,6 +416,24 @@ describe("sandbox file tools", () => { message: "Invalid glob: {foo,{bar,baz}}", }); + const literalNewline: SandboxCommandRunner = async () => ({ + exitCode: 2, + stderr: 'rg: the literal "\\n" is not allowed in a regex', + stdout: "", + }); + + await expect( + grepFiles({ + fs: memory.fs, + path: "src", + pattern: "foo\nbar", + runCommand: literalNewline, + }), + ).rejects.toMatchObject({ + name: "ToolInputError", + message: "Invalid regex pattern: foo\nbar", + }); + const lifecycleFailure = new Error("sandbox_stopped"); await expect( findFiles({