docs: fix link to GitHub workflow status
[poolifier.git] / src / pools / selection-strategies / worker-choice-strategy-context.ts
index 2b3c9fb68b33b1d4925f9dab7be3cf14b123bf88..5d26f82ba4f5784873c18eb037beed9b26a5e2f5 100644 (file)
@@ -131,13 +131,18 @@ export class WorkerChoiceStrategyContext<
    * Executes the worker choice strategy algorithm in the context.
    *
    * @returns The key of the worker node.
+   * @throws {@link https://nodejs.org/api/errors.html#class-error} If the worker node key is null or undefined.
    */
   public execute (): number {
-    return (
+    const workerNodeKey = (
       this.workerChoiceStrategies.get(
         this.workerChoiceStrategy
       ) as IWorkerChoiceStrategy
     ).choose()
+    if (workerNodeKey == null) {
+      throw new Error('Worker node key chosen is null or undefined')
+    }
+    return workerNodeKey
   }
 
   /**