From 81027aa51f531fe0d964be45634e0e20077ac328 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 28 Jul 2023 12:55:15 +0200 Subject: [PATCH] refactor: add sanity checks to worker set arguments MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/WorkerSet.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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, -- 2.34.1