diff --git a/lib/_debugger.js b/lib/_debugger.js index 4c503d2f5480e9..371e0ca56cf18e 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -1639,7 +1639,16 @@ Interface.prototype.trySpawn = function(cb) { } else if (this.args.length === 3) { // `node debug -p pid` if (this.args[1] === '-p' && /^\d+$/.test(this.args[2])) { - process._debugProcess(parseInt(this.args[2], 10)); + var pid = parseInt(this.args[2], 10); + try { + process._debugProcess(pid); + } catch (e) { + if (e.code === 'ESRCH') { + console.error('Target process: ' + pid + ' doesn\'t exists.'); + process.exit(1); + } + throw e; + } isRemote = true; } else { var match = this.args[1].match(/^--port=(\d+)$/); @@ -1705,6 +1714,7 @@ Interface.prototype.trySpawn = function(cb) { // If it's failed to connect 10 times then print failed message if (connectionAttempts >= 10) { self.stdout.write(' failed, please retry\n'); + process.exit(1); return; } setTimeout(attemptConnect, 500);