From fb226c9b812c3db625996c5fe29c667be15c388c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 27 Aug 2021 09:46:48 +0200 Subject: [PATCH] Ensure an error is throwed in object factories if implementation is not found 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 | 3 --- src/utils/performance-storage/StorageFactory.ts | 3 +-- src/worker/WorkerFactory.ts | 2 ++ 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index b018df60..5c899d5c 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -99,9 +99,6 @@ export default class Bootstrap { Bootstrap.storage.storePerformanceStatistics(msg.data); } }); - if (!Bootstrap.workerImplementation) { - throw new Error('Worker implementation not found'); - } } private logPrefix(): string { diff --git a/src/utils/performance-storage/StorageFactory.ts b/src/utils/performance-storage/StorageFactory.ts index 2012b500..9cd98916 100644 --- a/src/utils/performance-storage/StorageFactory.ts +++ b/src/utils/performance-storage/StorageFactory.ts @@ -2,7 +2,6 @@ import { JSONFileStorage } from './JSONFileStorage'; import { MongoDBStorage } from './MongoDBStorage'; import { Storage } from './Storage'; import { StorageType } from '../../types/Storage'; -import logger from '../Logger'; export class StorageFactory { // eslint-disable-next-line @typescript-eslint/no-empty-function @@ -20,7 +19,7 @@ export class StorageFactory { storageInstance = new MongoDBStorage(connectionURI, logPrefix); break; default: - logger.error(`${logPrefix} Unknown storage type: ${type}`); + throw new Error(`${logPrefix} Unknown storage type: ${type}`); } return storageInstance; } diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index af2c53f9..fdfd0cb4 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -35,6 +35,8 @@ export default class WorkerFactory { options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE; workerImplementation = new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay, options.poolOptions, messageListenerCallback); break; + default: + throw new Error(`Worker implementation type '${workerProcessType}' not found`); } return workerImplementation; } -- 2.34.1