From: Jérôme Benoit Date: Fri, 27 Aug 2021 07:46:48 +0000 (+0200) Subject: Ensure an error is throwed in object factories if implementation is not X-Git-Tag: v1.0.48~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=fb226c9b812c3db625996c5fe29c667be15c388c;p=e-mobility-charging-stations-simulator.git Ensure an error is throwed in object factories if implementation is not found Signed-off-by: Jérôme Benoit --- 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; }