From dc1458ffefd45c7abc15fae2e1f4f2b503922e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Sat, 15 Apr 2023 22:15:20 +0800 Subject: [PATCH] :bug: Fix: sync with picgo, suppress epiep error --- package.json | 1 + src/main/lifeCycle/errorHandler.ts | 20 +++++++++++++++++++- src/universal/types/global.d.ts | 6 +++++- yarn.lock | 5 +++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b8cfdbbb..94015578 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "dexie": "^3.2.3", "electron-updater": "^5.3.0", "element-plus": "^2.2.32", + "epipebomb": "^1.0.0", "fast-xml-parser": "^4.1.1", "form-data": "^4.0.0", "fs-extra": "^11.1.0", diff --git a/src/main/lifeCycle/errorHandler.ts b/src/main/lifeCycle/errorHandler.ts index 38b3b7e8..b851c4f7 100644 --- a/src/main/lifeCycle/errorHandler.ts +++ b/src/main/lifeCycle/errorHandler.ts @@ -9,7 +9,7 @@ const logger = getLogger(LOG_PATH, 'PicList') // since the error may occur in picgo-core // so we can't use the log from picgo -const handleProcessError = (error: Error) => { +const handleProcessError = (error: Error | string) => { logger('error', error) } @@ -20,3 +20,21 @@ process.on('uncaughtException', error => { process.on('unhandledRejection', (error: any) => { handleProcessError(error) }) + +// acconrding to https://github.com/Molunerfinn/PicGo/commit/7363be798cfef11e980934e542817ff1d6c04389#diff-896d0db4fbd446798fbffec14d456b4cd98d4c72c46856c770a585fa7ab0926f +function bootstrapEPIPESuppression () { + let suppressing = false + function logEPIPEErrorOnce () { + if (suppressing) { + return + } + + suppressing = true + handleProcessError('Detected EPIPE error; suppressing further EPIPE errors') + } + + require('epipebomb')(process.stdout, logEPIPEErrorOnce) + require('epipebomb')(process.stderr, logEPIPEErrorOnce) +} + +bootstrapEPIPESuppression() diff --git a/src/universal/types/global.d.ts b/src/universal/types/global.d.ts index d8b55adc..58a6be29 100644 --- a/src/universal/types/global.d.ts +++ b/src/universal/types/global.d.ts @@ -2,4 +2,8 @@ // https://stackoverflow.com/questions/35074713/extending-typescript-global-object-in-node-js/44387594#44387594 declare var PICGO_GUI_VERSION: string declare var PICGO_CORE_VERSION: string -declare var notificationList: IAppNotification[] \ No newline at end of file +declare var notificationList: IAppNotification[] + +declare module 'epipebomb' { + export default function epipebomb(stream: NodeJS.Process['stdout'], callback: () => void): void + } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 23d07d24..62b505a9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6829,6 +6829,11 @@ env-paths@^2.2.0: resolved "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz#420399d416ce1fbe9bc0a07c62fa68d67fd0f8f2" integrity sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A== +epipebomb@^1.0.0: + version "1.0.0" + resolved "https://registry.npmjs.org/epipebomb/-/epipebomb-1.0.0.tgz#57d1deda1d6bc81622b118a75fe6b5a7d34f6d88" + integrity sha512-NGv0bGlgetsi6ad5BuG1Pa9zpLLCeXeIa6wFGc+l0Emhr5rUlW8Rjx96NONlXZl4tMMaEODszyyy1A8ENjFoKA== + error-ex@^1.3.1: version "1.3.2" resolved "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"