Skip to content
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: refactor console in lib/internal/debugger/inspect.js #45847

Merged
merged 3 commits into from Dec 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions lib/internal/debugger/inspect.js
Expand Up @@ -32,9 +32,6 @@ const {
AbortController,
} = require('internal/abort_controller');

// TODO(aduh95): remove console calls
const console = require('internal/console/global');

const { 0: InspectClient, 1: createRepl } =
[
require('internal/debugger/inspect_client'),
Expand Down Expand Up @@ -319,7 +316,7 @@ function parseArgv(args) {
process._debugProcess(pid);
} catch (e) {
if (e.code === 'ESRCH') {
console.error(`Target process: ${pid} doesn't exist.`);
process.stderr.write(`Target process: ${pid} doesn't exist.\n`);
process.exit(kGenericUserError);
}
throw e;
Expand All @@ -339,10 +336,10 @@ function startInspect(argv = ArrayPrototypeSlice(process.argv, 2),
if (argv.length < 1) {
const invokedAs = `${process.argv0} ${process.argv[1]}`;

console.error(`Usage: ${invokedAs} script.js`);
console.error(` ${invokedAs} <host>:<port>`);
console.error(` ${invokedAs} --port=<port>`);
console.error(` ${invokedAs} -p <pid>`);
process.stderr.write(`Usage: ${invokedAs} script.js\n` +
` ${invokedAs} <host>:<port>\n` +
` ${invokedAs} --port=<port>\n` +
` ${invokedAs} -p <pid>\n`);
// TODO(joyeecheung): should be kInvalidCommandLineArgument.
process.exit(kGenericUserError);
}
Expand All @@ -354,12 +351,12 @@ function startInspect(argv = ArrayPrototypeSlice(process.argv, 2),

function handleUnexpectedError(e) {
if (e.code !== 'ERR_DEBUGGER_STARTUP_ERROR') {
console.error('There was an internal error in Node.js. ' +
'Please report this bug.');
console.error(e.message);
console.error(e.stack);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would be a difference if the inspect client listens to Runtime.consoleAPICalled, but I don't think it does currently.

process.stderr.write('There was an internal error in Node.js. ' +
'Please report this bug.\n' +
`${e.message}\n${e.stack}\n`);
} else {
console.error(e.message);
process.stderr.write(e.message);
process.stderr.write('\n');
}
if (inspector.child) inspector.child.kill();
process.exit(kGenericUserError);
Expand Down