From fdf9081a8f02604b05e55fd4d9a24aae60cec0db Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sun, 24 Mar 2024 14:58:34 +0800 Subject: [PATCH] once pipe for process communication get bad, exit process immediately --- packages/ui/src/main/flow/utils/pipe.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/main/flow/utils/pipe.ts b/packages/ui/src/main/flow/utils/pipe.ts index 6337a0a..d270be4 100644 --- a/packages/ui/src/main/flow/utils/pipe.ts +++ b/packages/ui/src/main/flow/utils/pipe.ts @@ -1,5 +1,6 @@ import * as fs from 'fs' import { type Stream } from 'stream' +import { app } from 'electron' const pipeSet = new WeakSet() export const pipeWriteRegardlessError = async ( @@ -10,8 +11,14 @@ export const pipeWriteRegardlessError = async ( if (pipe && !pipeSet.has(pipe)) { pipeSet.add(pipe) pipe.on('error', (error) => { - console.log('pipe.write Error', error) + void error }) } - return pipe?.write(chunk, option, () => {}) + return pipe?.write(chunk, option, (error) => { + if (error) { + console.log('pipe.write Error', error) + app.exit(1) + process.exit(1) + } + }) }