Refine error types thrown
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Oct 2022 21:14:12 +0000 (23:14 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Oct 2022 21:14:12 +0000 (23:14 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/worker/abstract-worker.ts
tests/pools/abstract/abstract-pool.test.js

index c9b8c795737a85338686df733c39397c39595201..72e830745558831db7933dfcfd5b6c8a03b35d78 100644 (file)
@@ -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) {
index c3c5d1bda82894265565f83bf662cc1618013edd..54358ee64b58adfb1a4f9275f53a04185ea878e8 100644 (file)
@@ -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
   }
 
index 273de9a038f0a02eb0e4d554bd717107e06394f3..80ebdb9e7e5a04b07f71f7878ed46318cbcd4fdb 100644 (file)
@@ -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'
       )
     )