refactor: add sanity check to worker script handling
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Apr 2023 16:45:19 +0000 (18:45 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Apr 2023 16:45:19 +0000 (18:45 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.vscode/settings.json
src/types/Storage.ts
src/types/index.ts
src/worker/WorkerAbstract.ts

index 06f6d6a01589ead1eb583feac816464e2bc4d90d..6099f4afc75f267f8d023cd6e52e372a05ebcfd7 100644 (file)
@@ -4,5 +4,6 @@
   },
   "testExplorer.useNativeTesting": true,
   "mochaExplorer.files": ["test/**/*Test.ts"],
-  "mochaExplorer.debuggerConfig": "Debug Simulator Unit Tests"
+  "mochaExplorer.debuggerConfig": "Debug Simulator Unit Tests",
+  "cSpell.words": ["CSMS", "iccid", "imsi", "Measurand", "Mikro", "ocpp", "poolifier"]
 }
index bb300c2387fc1e41cb57b01facdfc793f3c9926d..afb29e8267fc6d1943e6e0f3a2d8b990d32f00fd 100644 (file)
@@ -1,6 +1,6 @@
 import type { Configuration } from '@mikro-orm/core';
 
-export type MikroORMDBType = keyof typeof Configuration.PLATFORMS;
+export type MikroOrmDbType = keyof typeof Configuration.PLATFORMS;
 
 export enum StorageType {
   JSON_FILE = 'jsonfile',
index eaf26be9cbe4473979f9c99967b607badf83c5b5..1e1842de984f05249ad3843261b4553a3d17d7ea 100644 (file)
@@ -92,7 +92,7 @@ export {
   MeterValueUnit,
   type MeterValuesRequest,
   type MeterValuesResponse,
-  type MikroORMDBType,
+  type MikroOrmDbType as MikroORMDBType,
   OCPP16AuthorizationStatus,
   type OCPP16AuthorizeRequest,
   type OCPP16AuthorizeResponse,
index 3dd9a782a8661507f61fa21787ed9f80c9465852..16d566bde2ae60049fe401c7f13f830af4ce17dd 100644 (file)
@@ -27,9 +27,12 @@ export abstract class WorkerAbstract<T extends WorkerData> {
       messageHandler: WorkerConstants.EMPTY_FUNCTION,
     }
   ) {
-    if (!workerScript) {
+    if (workerScript === null || workerScript === undefined) {
       throw new Error('Worker script is not defined');
     }
+    if (typeof workerScript === 'string' && workerScript.trim().length === 0) {
+      throw new Error('Worker script is empty');
+    }
     if (!fs.existsSync(workerScript)) {
       throw new Error('Worker script file does not exist');
     }