From: Jérôme Benoit Date: Fri, 28 Jul 2023 10:55:15 +0000 (+0200) Subject: refactor: add sanity checks to worker set arguments X-Git-Tag: v1.2.20~111 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=81027aa51f531fe0d964be45634e0e20077ac328;p=e-mobility-charging-stations-simulator.git refactor: add sanity checks to worker set arguments Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index fd81840a..0f820411 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -35,6 +35,18 @@ export class WorkerSet extends WorkerAbstract { */ constructor(workerScript: string, workerOptions: WorkerOptions) { super(workerScript, workerOptions); + if ( + this.workerOptions.elementsPerWorker === null || + this.workerOptions.elementsPerWorker === undefined + ) { + throw new TypeError('Elements per worker is not defined'); + } + if (Number.isSafeInteger(this.workerOptions.elementsPerWorker)) { + throw new TypeError('Elements per worker must be an integer'); + } + if (this.workerOptions.elementsPerWorker <= 0) { + throw new RangeError('Elements per worker must be greater than zero'); + } this.workerOptions.poolOptions = { ...DEFAULT_POOL_OPTIONS, ...this.workerOptions.poolOptions,