-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debugger: improve ESRCH error message #1863
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
const pid = parseInt(this.args[2], 10); | ||
try { | ||
process._debugProcess(pid); | ||
} catch (e) { | ||
if (e.code === 'ESRCH') { | ||
console.error(`Target process: ${pid} doesn't exist.`); | ||
process.exit(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's better to update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default handle is too general, I don't know how to improve it.
|
||
} | ||
throw e; | ||
} | ||
isRemote = true; | ||
} else { | ||
var match = this.args[1].match(/^--port=(\d+)$/); | ||
|
@@ -1704,8 +1713,8 @@ Interface.prototype.trySpawn = function(cb) { | |
function connectError() { | ||
// If it's failed to connect 10 times then print failed message | ||
if (connectionAttempts >= 10) { | ||
self.stdout.write(' failed, please retry\n'); | ||
return; | ||
console.error(' failed, please retry'); | ||
process.exit(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a debug leftover? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It failed to connect target process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like an arbitrary change. Leaving the |
||
} | ||
setTimeout(attemptConnect, 500); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var spawn = require('child_process').spawn; | ||
|
||
var port = common.PORT + 1337; | ||
var buffer = ''; | ||
var expected = []; | ||
var scriptToDebug = common.fixturesDir + '/empty.js'; | ||
|
||
function fail() { | ||
assert(0); // `--debug-brk script.js` should not quit | ||
} | ||
|
||
// connect to debug agent | ||
var interfacer = spawn(process.execPath, ['debug', '-p', '655555']); | ||
|
||
console.error(process.execPath, 'debug', '-p', '655555'); | ||
interfacer.stdout.setEncoding('utf-8'); | ||
interfacer.stderr.setEncoding('utf-8'); | ||
var onData = function (data) { | ||
data = (buffer + data).split('\n'); | ||
buffer = data.pop(); | ||
data.forEach(function(line) { | ||
interfacer.emit('line', line); | ||
}); | ||
}; | ||
interfacer.stdout.on('data', onData); | ||
interfacer.stderr.on('data', onData); | ||
|
||
interfacer.on('line', function(line) { | ||
line = line.replace(/^(debug> *)+/, ''); | ||
var expected = 'Target process: 655555 doesn\'t exist.'; | ||
assert.ok(expected == line, 'Got unexpected line: ' + line); | ||
}); | ||
|
||
interfacer.on('exit', function (code, signal) { | ||
assert.ok(code == 1, 'Got unexpected code: ' + code); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question to reviewers.
process.bindings('uv')
has some error definitions like ESRCH.so we can write the following code :
is this better way? if any reviewer has some opinions, please tell me.
if this code is good, we can prevent some typos like
ESCRH
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's alright but I wouldn't write it like that myself, it's more lines of code and harder to grok than a simple string comparison. Typos shouldn't be an issue because there should be regression tests that catch those.