fix process.exit and uncaughtException code.

This commit is contained in:
Christopher Jeffrey 2014-09-18 14:54:08 -07:00
parent 84ea0890a8
commit 1f0413e262

View File

@ -47,15 +47,22 @@ Bitcoin.prototype.start = function(callback) {
process.exit = function(code) { process.exit = function(code) {
exitCaught = code || 0; exitCaught = code || 0;
if (!self._shutdown) { if (!self._shutdown) {
return self._exit(exitCaught); return self._exit(code);
} }
self.stop(); self.stop();
}; };
process.on('uncaughtException', function(err) { process.on('uncaughtException', function(err) {
if (process.listeners('uncaughtException').length > 1) {
return;
}
errorCaught = err; errorCaught = err;
if (!self._shutdown) { if (!self._shutdown) {
return self._exit(exitCaught !== none ? exitCaught : 1); if (err && err.stack) {
console.error(err.stack);
}
self._exit(1);
return;
} }
self.stop(); self.stop();
}); });
@ -91,7 +98,7 @@ Bitcoin.prototype.start = function(callback) {
} }
if (errorCaught !== none) { if (errorCaught !== none) {
if (errorCaught.stack) { if (errorCaught && errorCaught.stack) {
console.error(errorCaught.stack); console.error(errorCaught.stack);
} }
return self._exit(0); return self._exit(0);