From 49e2c1e5803904e807a0574f398cc517c05fe408 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 16 Dec 2023 20:25:43 +0100 Subject: [PATCH] refactor: refine worker factory arguments checking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/WorkerAbstract.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 5e5e6fdb..cd4dedf9 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -22,10 +22,13 @@ export abstract class WorkerAbstract { */ constructor(workerScript: string, workerOptions: WorkerOptions) { if (workerScript == null) { - throw new Error('Worker script is not defined'); + throw new TypeError('Worker script is not defined'); } - if (typeof workerScript === 'string' && workerScript.trim().length === 0) { - throw new Error('Worker script is empty'); + if (typeof workerScript !== 'string') { + throw new TypeError('Worker script must be a string'); + } + if (workerScript.trim().length === 0) { + throw new Error('Worker script is an empty string'); } if (!existsSync(workerScript)) { throw new Error('Worker script file does not exist'); -- 2.34.1