From af9cf611cb123dc7a83218792848e53a049014cb Mon Sep 17 00:00:00 2001 From: Oj Date: Sun, 17 Apr 2022 00:04:03 +0100 Subject: [PATCH] [Bootstrap] Integrate ErrorHandler --- src/bootstrap.js | 15 +++++++++++---- src/errorHandler.js | 25 ------------------------- 2 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 src/errorHandler.js diff --git a/src/bootstrap.js b/src/bootstrap.js index 51de6cc..dd15112 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -1,4 +1,4 @@ -const { app } = require('electron'); +const { app, dialog } = require('electron'); const { readFileSync } = require('fs'); const { join } = require('path'); @@ -14,8 +14,15 @@ global.releaseChannel = buildInfo.releaseChannel; log('BuildInfo', buildInfo); -const { fatal, handled, init: EHInit } = require('./errorHandler'); -EHInit(); +const fatal = e => { + log('Fatal', e); + + dialog.showMessageBox({ + type: 'error', + message: 'A fatal Javascript error occured', + detail: e?.stack ?? String(e) + }).then(() => app.quit()); +}; const splash = require('./splash'); @@ -69,7 +76,7 @@ const startUpdate = async () => { inst.on('host-updated', () => autoStart.update(() => {})); inst.on('unhandled-exception', fatal); inst.on('InconsistentInstallerState', fatal); - inst.on('update-error', handled); + inst.on('update-error', console.error); require('./firstRun').do(inst); } else { diff --git a/src/errorHandler.js b/src/errorHandler.js deleted file mode 100644 index 23b59f6..0000000 --- a/src/errorHandler.js +++ /dev/null @@ -1,25 +0,0 @@ -const { app, dialog } = require("electron"); - -exports.init = () => { - process.on('uncaughtException', err => { - const stack = err.stack ?? String(err); - console.warn(stack); - - // dialog.showErrorBox('A JavaScript error occurred in the main process', message); - }); -}; - - -exports.fatal = (err) => { - log('ErrorHandler', 'Fatal:', err); - - dialog.showMessageBox(null, { - type: 'error', - message: 'A fatal Javascript error occured', - detail: err?.stack ?? String(err) - }).then(() => app.quit()); -}; - -exports.handled = (err) => { - log('ErrorHandler', 'Handled:', err); -}; \ No newline at end of file