From ff12980b67495964563118418f88e66a5819b17d Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Wed, 14 Dec 2022 00:35:13 +0530 Subject: [PATCH 1/3] debugger: refactor console in lib/internal/debugger/inspect.js Refs: https://github.com/nodejs/node/pull/38406/ --- lib/internal/debugger/inspect.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index cddd0f426731d6..6266a65c1f635d 100644 --- a/lib/internal/debugger/inspect.js +++ b/lib/internal/debugger/inspect.js @@ -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'), @@ -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; @@ -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} :`); - console.error(` ${invokedAs} --port=`); - console.error(` ${invokedAs} -p `); + process.stderr.write(`Usage: ${invokedAs} script.js\n`); + process.stderr.write(` ${invokedAs} :\n`); + process.stderr.write(` ${invokedAs} --port=\n`); + process.stderr.write(` ${invokedAs} -p \n`); // TODO(joyeecheung): should be kInvalidCommandLineArgument. process.exit(kGenericUserError); } @@ -354,12 +351,15 @@ 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'); + process.stderr.write(e.message); + process.stderr.write('\n'); + process.stderr.write(e.stack); + process.stderr.write('\n'); } else { - console.error(e.message); + process.stderr.write(e.message); + process.stderr.write('\n'); } if (inspector.child) inspector.child.kill(); process.exit(kGenericUserError); From 1e4f985cd925e2bd1a90b23f3299d82c2823634c Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Wed, 14 Dec 2022 11:54:04 +0530 Subject: [PATCH 2/3] update message to use template string Co-authored-by: Antoine du Hamel --- lib/internal/debugger/inspect.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index 6266a65c1f635d..f589bfdb9fc357 100644 --- a/lib/internal/debugger/inspect.js +++ b/lib/internal/debugger/inspect.js @@ -352,11 +352,8 @@ function startInspect(argv = ArrayPrototypeSlice(process.argv, 2), function handleUnexpectedError(e) { if (e.code !== 'ERR_DEBUGGER_STARTUP_ERROR') { process.stderr.write('There was an internal error in Node.js. ' + - 'Please report this bug.\n'); - process.stderr.write(e.message); - process.stderr.write('\n'); - process.stderr.write(e.stack); - process.stderr.write('\n'); + 'Please report this bug.\n' + + `${e.message}\n${e.stack}\n`); } else { process.stderr.write(e.message); process.stderr.write('\n'); From 9c08a5b6b4102d5a29e4c4b6a2f216de02f6e790 Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Wed, 14 Dec 2022 11:54:20 +0530 Subject: [PATCH 3/3] update message to use template string Co-authored-by: Antoine du Hamel --- lib/internal/debugger/inspect.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/debugger/inspect.js b/lib/internal/debugger/inspect.js index f589bfdb9fc357..683feac01e981e 100644 --- a/lib/internal/debugger/inspect.js +++ b/lib/internal/debugger/inspect.js @@ -336,10 +336,10 @@ function startInspect(argv = ArrayPrototypeSlice(process.argv, 2), if (argv.length < 1) { const invokedAs = `${process.argv0} ${process.argv[1]}`; - process.stderr.write(`Usage: ${invokedAs} script.js\n`); - process.stderr.write(` ${invokedAs} :\n`); - process.stderr.write(` ${invokedAs} --port=\n`); - process.stderr.write(` ${invokedAs} -p \n`); + process.stderr.write(`Usage: ${invokedAs} script.js\n` + + ` ${invokedAs} :\n` + + ` ${invokedAs} --port=\n` + + ` ${invokedAs} -p \n`); // TODO(joyeecheung): should be kInvalidCommandLineArgument. process.exit(kGenericUserError); }