From 68b9b6c10acf342252e60c147302e53f100c1371 Mon Sep 17 00:00:00 2001 From: Swastik Prakash Date: Thu, 19 Mar 2026 17:30:01 +0530 Subject: [PATCH] fix: correct PID check, preserve stack traces, and add missing return after queue overflow reject Signed-off-by: Swastik Prakash --- src/JavaScriptEvaluator.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/JavaScriptEvaluator.ts b/src/JavaScriptEvaluator.ts index 42ed9ad..2da4623 100644 --- a/src/JavaScriptEvaluator.ts +++ b/src/JavaScriptEvaluator.ts @@ -47,6 +47,7 @@ export type EvalResponse = { timeout?: boolean // if true the promise is rejected due to timeout starvation?: boolean // if true the promise is rejected due to lack of child process message?: string; // if promise rejected due to a caught exception this will be set + stack?: string; elapsed?: number; // the elapsed time in ms to process the work item maxQueueDepthExceeded?: boolean // if true the promise is rejected because the queue is full } @@ -137,7 +138,8 @@ export class JavaScriptEvaluator { .catch(err => { console.log(err); reject({ - message: err.message + message: err.message, + stack: err.stack }); }); } @@ -145,7 +147,8 @@ export class JavaScriptEvaluator { catch (err: any) { console.log(err); reject({ - message: err.message + message: err.message, + stack: err.stack }); } }); @@ -169,6 +172,7 @@ export class JavaScriptEvaluator { }; if(this.queue.length >= this.options.maxQueueDepth) { reject({ maxQueueDepthExceeded: true, elapsed: 0 }); + return; } this.queue.push(workItem); this.processQueue(options); @@ -220,7 +224,7 @@ export class JavaScriptEvaluator { const workerPath = this.getWorkerPath(); // console.debug(`Worker path: ${workerPath}`); const worker = child_process.fork(workerPath, { timeout: options.timeout, env: {} }); - if (!worker.pid) { + if (worker.pid === undefined || worker.pid === null) { throw new Error('Failed to fork child process'); } this.workers.push(worker);