From ac9b02c2d8ddb0a014bbd74d9eb9aa01bfe7375e Mon Sep 17 00:00:00 2001 From: Michael Hollister Date: Thu, 1 May 2025 12:15:33 -0500 Subject: [PATCH] Electron: Log uncaught exceptions in main process --- receivers/electron/src/Main.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/receivers/electron/src/Main.ts b/receivers/electron/src/Main.ts index e60b847..0e9f702 100644 --- a/receivers/electron/src/Main.ts +++ b/receivers/electron/src/Main.ts @@ -10,7 +10,6 @@ import * as os from 'os'; import * as path from 'path'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import { ToastIcon } from 'common/components/Toast'; const cp = require('child_process'); let logger = null; @@ -389,6 +388,8 @@ export class Main { logger.info(`Release channel: ${Updater.releaseChannel} - ${Updater.getChannelVersion()}`); logger.info(`OS: ${process.platform} ${process.arch}`); + process.setUncaughtExceptionCaptureCallback(async (error) => await errorHandler(error)); + if (isUpdating) { await Updater.processUpdate(); } @@ -458,14 +459,14 @@ export function getComputerName() { } } -export async function errorHandler(err: NodeJS.ErrnoException) { - logger.error("Application error:", err); - Main.mainWindow?.webContents?.send("toast", { message: err, icon: ToastIcon.ERROR }); +export async function errorHandler(error: Error) { + logger.error(error); + logger.shutdown(); const restartPrompt = await dialog.showMessageBox({ type: 'error', title: 'Failed to start', - message: 'The application failed to start properly.', + message: `The application failed to start properly:\n\n${error.stack}}`, buttons: ['Restart', 'Close'], defaultId: 0, cancelId: 1