Skip to content

Commit

Permalink
🐛 Fix: sync with picgo, suppress epiep error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Apr 15, 2023
1 parent d5f7121 commit dc1458f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion src/main/lifeCycle/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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()
6 changes: 5 additions & 1 deletion src/universal/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
declare var notificationList: IAppNotification[]

declare module 'epipebomb' {
export default function epipebomb(stream: NodeJS.Process['stdout'], callback: () => void): void
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit dc1458f

Please sign in to comment.