mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
process: Use exit code 8 consistently
This should always be used in the case of an uncaughtException
This commit is contained in:
1 parent
a5dba82ee2
commit
6808706c3b
2 files changed
+17
-2
No files matched your search
+1
-1
@@ -233,7 +233,7 @@
|
||||
try {
|
||||
if (!process._exiting) {
|
||||
process._exiting = true;
|
||||
process.emit('exit', 1);
|
||||
process.emit('exit', 8);
|
||||
}
|
||||
} catch (er) {
|
||||
// nothing to be done about it at this point.
|
||||
|
||||
@@ -29,6 +29,8 @@ switch (process.argv[2]) {
|
||||
return child2();
|
||||
case 'child3':
|
||||
return child3();
|
||||
case 'child4':
|
||||
return child4();
|
||||
case undefined:
|
||||
return parent();
|
||||
default:
|
||||
@@ -58,17 +60,30 @@ function child3() {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function child4() {
|
||||
process.exitCode = 99;
|
||||
process.on('exit', function(code) {
|
||||
if (code !== 8) {
|
||||
console.log('wrong code! expected 8 for uncaughtException');
|
||||
process.exit(99);
|
||||
}
|
||||
});
|
||||
throw new Error('ok');
|
||||
}
|
||||
|
||||
function parent() {
|
||||
test('child1', 42);
|
||||
test('child2', 42);
|
||||
test('child3', 0);
|
||||
test('child4', 8);
|
||||
}
|
||||
|
||||
function test(arg, exit) {
|
||||
var spawn = require('child_process').spawn;
|
||||
var node = process.execPath;
|
||||
var f = __filename;
|
||||
spawn(node, [f, arg], {stdio: 'inherit'}).on('exit', function(code) {
|
||||
var option = { stdio: [ 0, 1, 'ignore' ] };
|
||||
spawn(node, [f, arg], option).on('exit', function(code) {
|
||||
assert.equal(code, exit, 'wrong exit for ' +
|
||||
arg + '\nexpected:' + exit +
|
||||
' but got:' + code);
|
||||
|
||||
Reference in new issue
Block a user