From 1b8648acabb1063df75db0ede942b495c2ba86e8 Mon Sep 17 00:00:00 2001 From: BJR Matos Date: Mon, 24 Apr 2017 17:38:05 -0500 Subject: [PATCH] add worker error message into error returned from manager --- lib/phantomManager.js | 11 ++++++----- lib/phantomWorker.js | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/phantomManager.js b/lib/phantomManager.js index f2e5e19..0ff8dc0 100644 --- a/lib/phantomManager.js +++ b/lib/phantomManager.js @@ -37,6 +37,7 @@ PhantomManager.prototype.start = function (cb) { var started = 0; var workerErrors = []; var couldNotStartWorkersErr; + var workerMainErrorMsg = ''; for (var i = 0; i < self.options.numberOfWorkers; i++) { self._phantomInstances.push(new PhantomWorker({ @@ -51,6 +52,10 @@ PhantomManager.prototype.start = function (cb) { })); self._phantomInstances[i].start(function(err) { if (err) { + if (err.mainReason && workerMainErrorMsg === '') { + workerMainErrorMsg = err.mainReason; + } + workerErrors.push(err); } @@ -58,7 +63,7 @@ PhantomManager.prototype.start = function (cb) { if (started === self.options.numberOfWorkers) { if (workerErrors.length) { - couldNotStartWorkersErr = new Error("phantom manager could not start all workers.."); + couldNotStartWorkersErr = new Error("phantom manager could not start all workers.." + workerMainErrorMsg); couldNotStartWorkersErr.workerErrors = workerErrors; return cb(couldNotStartWorkersErr); } @@ -152,7 +157,3 @@ PhantomManager.prototype.tryFlushQueue = function () { this._executeInWorker(freePhantomInstance, task.options, task.cb); }; - - - - diff --git a/lib/phantomWorker.js b/lib/phantomWorker.js index d5233a9..68ace57 100644 --- a/lib/phantomWorker.js +++ b/lib/phantomWorker.js @@ -91,13 +91,18 @@ PhantomWorker.prototype.start = function (cb) { //we send host and port as env vars to child process self._childProcess = childProcess.execFile(self.options.phantomPath, childArgs, childOpts, function (error, stdout, stderr) { + var segFaultMsg; + if (error) { if (error.signal === 'SIGSEGV') { - error.message = ( - error.message + ', Segmentation fault error: if you are using macOS Sierra with phantomjs < 2 remember that ' + + segFaultMsg = ( + 'Segmentation fault error: if you are using macOS Sierra with phantomjs < 2 remember that ' + 'phantomjs < 2 does not work there and has bugs (https://github.com/ariya/phantomjs/issues/14558), ' + 'try to upgrade to phantom 2 if using macOS Sierra' ); + + error.message = error.message + ', ' + segFaultMsg; + error.mainReason = segFaultMsg; } startError = error