From 473c717a499d52ce8a069c43ee168b70cb5701f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 21 Oct 2022 23:14:12 +0200 Subject: [PATCH] Refine error types thrown MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 4 ++-- src/worker/abstract-worker.ts | 3 --- tests/pools/abstract/abstract-pool.test.js | 6 ++++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index c9b8c795..72e83074 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -126,11 +126,11 @@ export abstract class AbstractPool< 'Cannot instantiate a pool without specifying the number of workers' ) } else if (Number.isSafeInteger(numberOfWorkers) === false) { - throw new Error( + throw new TypeError( 'Cannot instantiate a pool with a non integer number of workers' ) } else if (numberOfWorkers < 0) { - throw new Error( + throw new RangeError( 'Cannot instantiate a pool with a negative number of workers' ) } else if (this.type === PoolType.FIXED && numberOfWorkers === 0) { diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index c3c5d1bd..54358ee6 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -104,9 +104,6 @@ export abstract class AbstractWorker< this.opts.killBehavior = opts.killBehavior ?? DEFAULT_KILL_BEHAVIOR this.opts.maxInactiveTime = opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME - /** - * Whether the worker is working asynchronously or not. - */ this.opts.async = !!opts.async } diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 273de9a0..80ebdb9e 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -62,7 +62,9 @@ describe('Abstract pool test suite', () => { () => new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js') ).toThrowError( - new Error('Cannot instantiate a pool with a negative number of workers') + new RangeError( + 'Cannot instantiate a pool with a negative number of workers' + ) ) }) @@ -71,7 +73,7 @@ describe('Abstract pool test suite', () => { () => new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.js') ).toThrowError( - new Error( + new TypeError( 'Cannot instantiate a pool with a non integer number of workers' ) ) -- 2.34.1