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 <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
  • Loading branch information
debadree25 authored and juanarbol committed Jan 31, 2023
1 parent 61dbca2 commit 4cdf000
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 @@ -312,7 +309,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(1);
}
throw e;
Expand All @@ -332,10 +329,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`);
process.exit(1);
}

Expand All @@ -346,12 +343,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(1);
Expand Down

0 comments on commit 4cdf000

Please sign in to comment.