{"record":{"id":"3a84bdd254874470","repo":"run-llama/liteparse","slug":"poolsize-must-be-an-integer-1","errorCode":null,"errorMessage":"poolSize must be an integer >= 1","messagePattern":"poolSize must be an integer >= 1","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/node/src/pool.ts","lineNumber":202,"sourceCode":"\nexport class WorkerPool {\n  private config: Record<string, unknown>;\n  private timeoutMs: number | undefined;\n  private workers = new Set<WorkerHandle>();\n  private idle: WorkerHandle[] = [];\n  private waiters: Array<{\n    resolve: (w: WorkerHandle) => void;\n    reject: (e: Error) => void;\n  }> = [];\n  private closed = false;\n\n  constructor(\n    config: Record<string, unknown>,\n    poolSize: number,\n    parseTimeoutMs?: number,\n  ) {\n    if (!Number.isInteger(poolSize) || poolSize < 1) {\n      throw new Error(\"poolSize must be an integer >= 1\");\n    }\n    if (parseTimeoutMs !== undefined && !(parseTimeoutMs > 0)) {\n      throw new Error(\"parseTimeoutMs must be > 0\");\n    }\n    this.config = config;\n    this.timeoutMs = parseTimeoutMs;\n    // Spawn eagerly: children load the addon and construct their native\n    // parsers concurrently while the caller goes on with its own startup.\n    for (let i = 0; i < poolSize; i++) {\n      this.spawnWorker();\n    }\n  }\n\n  private spawnWorker(): void {\n    const worker = new WorkerHandle(this.config);\n    this.workers.add(worker);\n    this.release(worker);\n  }","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/run-llama/liteparse/blob/22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8/packages/node/src/pool.ts#L184-L220","documentation":"WorkerPool's constructor validates that poolSize is a whole number of at least 1 before spawning workers. A non-integer (0.5, NaN, Infinity) or a value below 1 would produce a broken or empty pool, so it throws immediately. This is a fail-fast guard for programmatic configuration mistakes.","triggerScenarios":"`new WorkerPool(config, 0)`, a fractional poolSize from computing `maxWorkers / 2`, or NaN/undefined leaking from env parsing like `Number(process.env.POOL_SIZE)` when the variable is unset or garbage.","commonSituations":"Env-var-driven config where POOL_SIZE is empty string (Number('') === 0); dividing a worker count and flooring incorrectly; passing user-supplied values straight into the pool config.","solutions":["Pass an integer >= 1: `new WorkerPool(config, 4)`.","Sanitize env-derived values: `const n = Math.max(1, Math.floor(Number(process.env.POOL_SIZE ?? 2)))`.","Guard before construction: `if (!Number.isInteger(poolSize) || poolSize < 1) poolSize = 2;`"],"exampleFix":"// before\nconst pool = new WorkerPool(cfg, Number(process.env.POOL_SIZE));\n// after\nconst n = Math.max(1, Math.floor(Number(process.env.POOL_SIZE) || 2));\nconst pool = new WorkerPool(cfg, n);","handlingStrategy":"validation","validationCode":"const n = Math.floor(Number(process.env.POOL_SIZE));\nif (!Number.isInteger(n) || n < 1) {\n  throw new Error(`POOL_SIZE must be an integer >= 1, got ${process.env.POOL_SIZE}`);\n}","typeGuard":"const isValidPoolSize = (v) => typeof v === 'number' && Number.isInteger(v) && v >= 1;","tryCatchPattern":"let pool;\ntry {\n  pool = new WorkerPool(config, poolSize, timeoutMs);\n} catch (e) {\n  if (e.message === 'poolSize must be an integer >= 1') {\n    pool = new WorkerPool(config, 2, timeoutMs);\n  } else throw e;\n}","preventionTips":["Sanitize env-derived numbers with Number.isInteger before use.","Use Math.max(1, Math.floor(x)) for computed pool sizes.","Avoid raw user input flowing into poolSize."],"tags":["worker-pool","configuration","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"22d2dd8cd7f7b9320102b57ddaf0e663ff7d15a8","analyzedAt":"2026-09-08T06:09:49.009Z","contentChangedAt":"2026-09-08T06:09:49.009Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}