fix(core): handle EPIPE error in hook runner when writing to stdin (#14231)

This commit is contained in:
Sandy Tao
2025-12-02 00:58:41 +08:00
committed by GitHub
parent f2466e5224
commit 2fe609cb62
3 changed files with 8 additions and 0 deletions

View File

@@ -64,6 +64,7 @@ describe('HookRunner', () => {
stdin: {
write: vi.fn(),
end: vi.fn(),
on: vi.fn(),
} as unknown as Writable,
stdout: {
on: mockStdoutOn,

View File

@@ -232,6 +232,12 @@ export class HookRunner {
// Send input to stdin
if (child.stdin) {
child.stdin.on('error', (err: NodeJS.ErrnoException) => {
// Ignore EPIPE errors which happen when the child process closes stdin early
if (err.code !== 'EPIPE') {
debugLogger.warn(`Hook stdin error: ${err}`);
}
});
child.stdin.write(JSON.stringify(input));
child.stdin.end();
}

View File

@@ -96,6 +96,7 @@ describe('HookSystem Integration', () => {
stdin: {
write: vi.fn(),
end: vi.fn(),
on: vi.fn(),
} as unknown as Writable,
stdout: {
on: mockStdoutOn,