From ba516f9cbce4070d1b5eda82a2cd48b82a67c500 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Apr 2023 18:45:19 +0200 Subject: [PATCH] refactor: add sanity check to worker script handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .vscode/settings.json | 3 ++- src/types/Storage.ts | 2 +- src/types/index.ts | 2 +- src/worker/WorkerAbstract.ts | 5 ++++- 4 files changed, 8 insertions(+), 4 deletions(-) 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'); } -- 2.34.1