Skip to content

Commit

Permalink
debugger: refactor console in lib/internal/debugger/inspect.js
Browse files Browse the repository at this point in the history
Refs: #38406
PR-URL: #45847
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Kohei Ueno <[email protected]>
  • Loading branch information
debadree25 authored and targos committed Jan 1, 2023
1 parent 0043eef commit e2594ac
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/internal/debugger/inspect.js
Original file line number Diff line number Diff line change
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 @@ -318,7 +315,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 @@ -338,10 +335,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 @@ -353,12 +350,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);
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

0 comments on commit e2594ac

Please sign in to comment.