From: Jérôme Benoit Date: Fri, 16 Sep 2022 16:53:36 +0000 (+0200) Subject: Log unconditionally uncaughtException and unhandledRejection in X-Git-Tag: v1.1.74~33 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=48d17ce2fd55a8b0d49d80263f3ffd16bcfe89b0;p=e-mobility-charging-stations-simulator.git Log unconditionally uncaughtException and unhandledRejection in Bootstrap Signed-off-by: Jérôme Benoit --- 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); } }