refactor: add sanity check at getting worker info
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 19 Jul 2023 22:49:12 +0000 (00:49 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 19 Jul 2023 22:49:12 +0000 (00:49 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts

index ddf4cbccd64f0f29e70b7f2994b4c2cc543626f3..be1402a7eccf3e9a81d5e7736f61ed7751d1720a 100644 (file)
@@ -1066,7 +1066,11 @@ export abstract class AbstractPool<
    * @param worker - The worker.
    */
   protected getWorkerInfoByWorker (worker: Worker): WorkerInfo {
-    return this.workerNodes[this.getWorkerNodeKey(worker)].info
+    const workerNodeKey = this.getWorkerNodeKey(worker)
+    if (workerNodeKey === -1) {
+      throw new Error('Worker not found')
+    }
+    return this.workerNodes[workerNodeKey].info
   }
 
   /**