Ensure an error is throwed in object factories if implementation is not
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Aug 2021 07:46:48 +0000 (09:46 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 27 Aug 2021 07:46:48 +0000 (09:46 +0200)
found

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/charging-station/Bootstrap.ts
src/utils/performance-storage/StorageFactory.ts
src/worker/WorkerFactory.ts

index b018df60949332198edd94128c10c53505f98cd9..5c899d5c381220d3657e5c566e08abaf886aed52 100644 (file)
@@ -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 {
index 2012b500e544485c8f0f607ea4d9b89a5ac363a4..9cd9891630b2a295f5e9f4e540de1d3ced664f8a 100644 (file)
@@ -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;
   }
index af2c53f9b3d5c86817a4204bb806fe53a3917f50..fdfd0cb4a799b844b4bfd467bb7f6bc3c430e9b7 100644 (file)
@@ -35,6 +35,8 @@ export default class WorkerFactory {
         options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE;
         workerImplementation = new WorkerDynamicPool<T>(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay, options.poolOptions, messageListenerCallback);
         break;
+      default:
+        throw new Error(`Worker implementation type '${workerProcessType}' not found`);
     }
     return workerImplementation;
   }