fix: test for worker file existence
[poolifier.git] / src / pools / abstract-pool.ts
index 27d8af0f72713d6a5e224594f221d2f1b9591eec..f1392edd5124e25421531fec9958a2fea610bf59 100644 (file)
@@ -1,5 +1,6 @@
 import { randomUUID } from 'node:crypto'
 import { performance } from 'node:perf_hooks'
+import { existsSync } from 'node:fs'
 import type {
   MessageValue,
   PromiseResponseWrapper,
@@ -137,10 +138,14 @@ export abstract class AbstractPool<
   private checkFilePath (filePath: string): void {
     if (
       filePath == null ||
+      typeof filePath !== 'string' ||
       (typeof filePath === 'string' && filePath.trim().length === 0)
     ) {
       throw new Error('Please specify a file with a worker implementation')
     }
+    if (!existsSync(filePath)) {
+      throw new Error(`Cannot find the worker file '${filePath}'`)
+    }
   }
 
   private checkNumberOfWorkers (numberOfWorkers: number): void {