Resolves the confusing error message `ripgrep exited with code null that occurs when a search operation is cancelled or aborted (#14267)

Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
This commit is contained in:
Maxim Masiutin
2026-01-25 21:02:37 +02:00
committed by GitHub
parent fd36d65723
commit 4d197c992d
2 changed files with 10 additions and 6 deletions

View File

@@ -1009,10 +1009,10 @@ describe('RipGrepTool', () => {
const result = await invocation.execute(controller.signal);
expect(result.llmContent).toContain(
'Error during grep search operation: ripgrep exited with code null',
'Error during grep search operation: ripgrep was terminated by signal:',
);
expect(result.returnDisplay).toContain(
'Error: ripgrep exited with code null',
'Error: ripgrep was terminated by signal:',
);
});
});

View File

@@ -432,7 +432,7 @@ class GrepToolInvocation extends BaseToolInvocation<
);
});
child.on('close', (code) => {
child.on('close', (code, signal) => {
options.signal.removeEventListener('abort', cleanup);
const stdoutData = Buffer.concat(stdoutChunks).toString('utf8');
const stderrData = Buffer.concat(stderrChunks).toString('utf8');
@@ -442,9 +442,13 @@ class GrepToolInvocation extends BaseToolInvocation<
} else if (code === 1) {
resolve(''); // No matches found
} else {
reject(
new Error(`ripgrep exited with code ${code}: ${stderrData}`),
);
if (signal) {
reject(new Error(`ripgrep was terminated by signal: ${signal}`));
} else {
reject(
new Error(`ripgrep exited with code ${code}: ${stderrData}`),
);
}
}
});
});