Skip to content

Commit bf9bffa

Browse files
committed
debugger: improve ESRCH error message
When use `iojs debug -p <pid>` with an invalid pid, the debugger print internal error message also, it not enough smart.
1 parent c0e7bf2 commit bf9bffa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/_debugger.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,16 @@ Interface.prototype.trySpawn = function(cb) {
16391639
} else if (this.args.length === 3) {
16401640
// `node debug -p pid`
16411641
if (this.args[1] === '-p' && /^\d+$/.test(this.args[2])) {
1642-
process._debugProcess(parseInt(this.args[2], 10));
1642+
const pid = parseInt(this.args[2], 10);
1643+
try {
1644+
process._debugProcess(pid);
1645+
} catch (e) {
1646+
if (e.code === 'ESRCH') {
1647+
console.error('Target process: ' + pid + ' doesn\'t exist.');
1648+
process.exit(1);
1649+
}
1650+
throw e;
1651+
}
16431652
isRemote = true;
16441653
} else {
16451654
var match = this.args[1].match(/^--port=(\d+)$/);
@@ -1705,7 +1714,7 @@ Interface.prototype.trySpawn = function(cb) {
17051714
// If it's failed to connect 10 times then print failed message
17061715
if (connectionAttempts >= 10) {
17071716
self.stdout.write(' failed, please retry\n');
1708-
return;
1717+
process.exit(1);
17091718
}
17101719
setTimeout(attemptConnect, 500);
17111720
}

0 commit comments

Comments
 (0)