From 5db4b9efd89778fe8849e1411908bf3b0f0c7a5e Mon Sep 17 00:00:00 2001 From: Matt Lyons Date: Wed, 10 Jan 2024 14:40:02 -0600 Subject: [PATCH] Log unhandled exceptions and highlight module loading oddity (#703) --- src/renderer/index.tsx | 5 +++++ src/shared/services/logger.service.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/renderer/index.tsx b/src/renderer/index.tsx index bdc87c1045..2d9c864f1e 100644 --- a/src/renderer/index.tsx +++ b/src/renderer/index.tsx @@ -10,6 +10,11 @@ import App from './app.component'; import { cleanupOldWebViewState } from './services/web-view-state.service'; import { blockWebSocketsToPapiNetwork } from './services/renderer-web-socket.service'; +window.addEventListener('error', (errorEvent: ErrorEvent) => { + const { filename, lineno, colno, error } = errorEvent; + logger.error(`Unhandled error in renderer from ${filename}:${lineno}:${colno}, '${error}'`); +}); + logger.info('Starting renderer'); // This is a little different than Promise.all in that the error message will have all the reasons diff --git a/src/shared/services/logger.service.ts b/src/shared/services/logger.service.ts index ea7b78c89e..1db42be1f1 100644 --- a/src/shared/services/logger.service.ts +++ b/src/shared/services/logger.service.ts @@ -124,7 +124,7 @@ if (isClient()) { ), }; }); - if (isExtensionHost()) + else if (isExtensionHost()) // Add a tag for warnings so we can recognize them outside the process. log.hooks.push((message) => { const caller = identifyCaller(); @@ -136,6 +136,10 @@ if (isClient()) { ), }; }); + else { + // eslint-disable-next-line no-console + console.warn(chalk.yellow(`Unexpected process type: ${globalThis.processType}`)); + } } else { log.initialize(); log.transports.console.level = globalThis.logLevel;