Skip to content

Commit 83d6b55

Browse files
authored
fix: enhance IPC error handling (#54)
1 parent 01ee928 commit 83d6b55

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/rpc/expose-rpc.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import process from 'process';
2-
1+
import process from 'node:process';
32
import type { RpcMessage } from './types';
43

4+
function isClosedIpcChannelError(error: unknown): boolean {
5+
if (typeof error === 'object' && error !== null && 'code' in error) {
6+
const CLOSED_IPC_ERROR_CODES = new Set(['ERR_IPC_CHANNEL_CLOSED', 'EPIPE']);
7+
return CLOSED_IPC_ERROR_CODES.has(error.code as string);
8+
}
9+
return false;
10+
}
11+
512
// eslint-disable-next-line @typescript-eslint/no-explicit-any
613
export function exposeRpc(fn: (...args: any[]) => any) {
714
const sendMessage = (message: RpcMessage) =>
@@ -50,6 +57,13 @@ export function exposeRpc(fn: (...args: any[]) => any) {
5057
});
5158
}
5259
} catch (sendError) {
60+
if (isClosedIpcChannelError(sendError)) {
61+
console.warn(
62+
'[type-check] Skipped because the parent process exited. Build may have failed or been interrupted.',
63+
);
64+
return;
65+
}
66+
5367
// we can't send things back to the parent process - let's use stdout to communicate error
5468
if (error) {
5569
console.error(error);

0 commit comments

Comments
 (0)