From: Jérôme Benoit Date: Mon, 24 Apr 2023 16:45:19 +0000 (+0200) Subject: refactor: add sanity check to worker script handling X-Git-Tag: v1.2.12~92 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ba516f9cbce4070d1b5eda82a2cd48b82a67c500;p=e-mobility-charging-stations-simulator.git refactor: add sanity check to worker script handling Signed-off-by: Jérôme Benoit --- diff --git a/.vscode/settings.json b/.vscode/settings.json index 06f6d6a0..6099f4af 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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"] } diff --git a/src/types/Storage.ts b/src/types/Storage.ts index bb300c23..afb29e82 100644 --- a/src/types/Storage.ts +++ b/src/types/Storage.ts @@ -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', diff --git a/src/types/index.ts b/src/types/index.ts index eaf26be9..1e1842de 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -92,7 +92,7 @@ export { MeterValueUnit, type MeterValuesRequest, type MeterValuesResponse, - type MikroORMDBType, + type MikroOrmDbType as MikroORMDBType, OCPP16AuthorizationStatus, type OCPP16AuthorizeRequest, type OCPP16AuthorizeResponse, diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 3dd9a782..16d566bd 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -27,9 +27,12 @@ export abstract class WorkerAbstract { 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'); }