Skip to content

Commit 292b61d

Browse files
committed
bug fixes for Error on on fulfills
1 parent 9de185a commit 292b61d

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name":"stateful-process-command-proxy",
3-
"version":"1.0.0-beta.3",
4-
"description":"Module for executing os commands against a pool of stateful child processes such as bash or powershell via stdout and stderr streams",
3+
"version":"1.0.0-beta.4",
4+
"description":"Module for executing commands in shells (bash or powershell etc) against a pool of stateful child processes such as bash or powershell via stdout and stderr streams",
55
"main":"statefulProcessCommandProxy.js",
66
"directories":{
77
"test":"test"
@@ -12,7 +12,6 @@
1212
"keywords":[
1313
"command",
1414
"process",
15-
"os",
1615
"dos",
1716
"unix",
1817
"commandline",

processProxy.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ ProcessProxy.prototype._parseRegexes = function(regexesToParse, regexpsToAppendT
282282

283283
} catch(exception) {
284284
this._log('error',"Error parsing invalidation regex: "
285-
+ regexStr + " err:"+exception);
285+
+ regexStr + " err:"+exception + ' ' + exception.stack);
286286
}
287287
}
288288
}
@@ -314,7 +314,7 @@ ProcessProxy.prototype._parseRegexConfigs = function(regexConfigsToConvert) {
314314
} catch(exception) {
315315
delete regexConf.regex;
316316
this._log('error',"Error parsing regex: "
317-
+ regexStr + " err:"+exception);
317+
+ regexStr + " err:"+exception + ' ' + exception.stack);
318318
}
319319
}
320320
}
@@ -520,6 +520,10 @@ ProcessProxy.prototype.onData = function(type, data) {
520520
*
521521
* initCommands - array of commands to execute after the process
522522
* is successfully spawned.
523+
*
524+
* Returns a promise
525+
* - on fulfill the cmdResults from any initialize comamnds, otherwise fulfill(null)
526+
* - on reject, an Error object
523527
**/
524528
ProcessProxy.prototype.initialize = function(initCommands) {
525529

@@ -554,6 +558,7 @@ ProcessProxy.prototype.initialize = function(initCommands) {
554558
// register error handler
555559
self._process.on('error', function(err) {
556560
self._log('error','child process received error ' + err);
561+
self._isValid = false; // set us to invalid
557562
});
558563

559564
// register exit handler
@@ -594,7 +599,8 @@ ProcessProxy.prototype.initialize = function(initCommands) {
594599

595600

596601
} catch (exception) {
597-
self._log('error',"initialize, exception thrown: " + exception);
602+
self._log('error',"initialize, exception thrown: "
603+
+ exception + ' ' + exception.stack);
598604
reject(exception);
599605
}
600606

@@ -712,7 +718,7 @@ ProcessProxy.prototype._evalRegexConfigs = function(regexConfs, dataToEval) {
712718
/**
713719
* executeCommand - takes a raw command statement and returns a promise
714720
* which fulfills/returns {command:cmd, stdout:xxxx, stderr:xxxxx}
715-
* on reject gives an exception
721+
* on reject give an Error object
716722
*
717723
**/
718724
ProcessProxy.prototype.executeCommand = function(command) {
@@ -747,7 +753,8 @@ ProcessProxy.prototype.executeCommand = function(command) {
747753
* @commands Array of raw command/shell statements to be executed
748754
*
749755
* @return Promise, on fulfill returns promise to be fulfilled with a
750-
* array of command results as described above
756+
* array of command results as described above, on reject
757+
* and Error object
751758
*
752759
**/
753760
ProcessProxy.prototype.executeCommands = function(commands) {
@@ -816,7 +823,8 @@ ProcessProxy.prototype.executeCommands = function(commands) {
816823
* underlying child process being proxied WILL be KILLED.
817824
*
818825
* shutdownCommands - optional array of commands to execute before the process
819-
* is attempted to be shutdown.
826+
* is attempted to be shutdown. On fulfill will return cmdResults
827+
* of all destroy commands (if configured), on reject and Error
820828
**/
821829
ProcessProxy.prototype.shutdown = function(shutdownCommands) {
822830

statefulProcessCommandProxy.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ function StatefulProcessCommandProxy(config) {
148148
callback(null, processProxy);
149149

150150
}).catch(function(exception) {
151-
self._log('error',"new process initialize threw error: " + exception);
151+
self._log('error',"new process initialize threw error: " + exception + ' ' + exception.stack);
152152
});
153153

154154
} catch (exception) {
155-
self._log('error',"create: exception: " + exception);
155+
self._log('error',"create: exception: " + exception + ' ' + exception.stack);
156156
callback(exception, null);
157157
}
158158
},
@@ -253,7 +253,7 @@ StatefulProcessCommandProxy.prototype.getStatus = function() {
253253

254254
} catch(exception) {
255255
self._log('error', "getStatus[process:" +
256-
processProxy.getPid() + "]: error: " + e);
256+
processProxy.getPid() + "]: error: " + exception);
257257
}
258258
}
259259

@@ -357,21 +357,21 @@ StatefulProcessCommandProxy.prototype.executeCommands = function(commands) {
357357
try {
358358
processProxy.executeCommands(commands)
359359

360-
.then(function(cmdResults) {
360+
.then(function(cmdResults) {
361361

362-
try {
363-
fulfill(cmdResults);
362+
try {
363+
fulfill(cmdResults);
364364

365-
} finally {
366-
self._pool.release(processProxy);
367-
}
365+
} finally {
366+
self._pool.release(processProxy);
367+
}
368368

369-
}).catch(function(error) {
370-
self._log('error',"executeCommands: [" +
371-
commands + "] error: " + e);
372-
self._pool.release(processProxy);
373-
reject(error);
374-
});
369+
}).catch(function(error) {
370+
self._log('error',"executeCommands: [" +
371+
commands + "] error: " + error);
372+
self._pool.release(processProxy);
373+
reject(error);
374+
});
375375

376376
} catch (e) {
377377
self._log('error',"executeCommands: error: " + e);

0 commit comments

Comments
 (0)