From 48d17ce2fd55a8b0d49d80263f3ffd16bcfe89b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 16 Sep 2022 18:53:36 +0200 Subject: [PATCH] Log unconditionally uncaughtException and unhandledRejection in Bootstrap MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 15 +++++++++++++++ src/charging-station/ChargingStationWorker.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 85f8f371..7c80067c 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -75,6 +75,9 @@ export class Bootstrap { public async start(): Promise { if (isMainThread && this.started === false) { try { + // Enable unconditionally for now + this.logUnhandledRejection(); + this.logUncaughtException(); this.initialize(); await this.storage?.open(); await this.workerImplementation.start(); @@ -244,6 +247,18 @@ export class Bootstrap { this.initializeWorkerImplementation(); } + private logUncaughtException(): void { + process.on('uncaughtException', (error: Error) => { + console.error(chalk.red('Uncaught exception: '), error); + }); + } + + private logUnhandledRejection(): void { + process.on('unhandledRejection', (reason: unknown) => { + console.error(chalk.red('Unhandled rejection: '), reason); + }); + } + private async startChargingStation( index: number, stationTemplateUrl: StationTemplateUrl diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index 626e6e07..4f109bf5 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -24,7 +24,7 @@ if (ChargingStationUtils.workerPoolInUse()) { } else { // Add message listener to start charging station from main thread addMessageListener(); - if (!Utils.isUndefined(workerData)) { + if (Utils.isUndefined(workerData) === false) { startChargingStation(workerData as ChargingStationWorkerData); } } -- 2.34.1