From ca792acdd4ba683d8415c88188ec6739033fb4fd Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 15 Sep 2021 11:12:49 -0700 Subject: [PATCH] fix(logs): clean args for failed commands PR-URL: https://github.com/npm/cli/pull/3761 Credit: @wraithgar Close: #3761 Reviewed-by: @lukekarrys --- lib/utils/error-message.js | 2 +- .../test/lib/utils/error-message.js.test.cjs | 34 +++++++++++++++++++ test/lib/utils/error-message.js | 11 ++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 6e12bcb918eef..9343d37d54149 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -367,7 +367,7 @@ module.exports = (er, npm) => { detail.push(['signal', er.signal]) if (er.cmd && Array.isArray(er.args)) - detail.push(['command', ...[er.cmd, ...er.args]]) + detail.push(['command', ...[er.cmd, ...er.args.map(replaceInfo)]]) if (er.stdout) detail.push(['', er.stdout.trim()]) diff --git a/tap-snapshots/test/lib/utils/error-message.js.test.cjs b/tap-snapshots/test/lib/utils/error-message.js.test.cjs index 1f73361c48589..79301bfaa0cf0 100644 --- a/tap-snapshots/test/lib/utils/error-message.js.test.cjs +++ b/tap-snapshots/test/lib/utils/error-message.js.test.cjs @@ -180,6 +180,40 @@ Object { } ` +exports[`test/lib/utils/error-message.js TAP args are cleaned > must match snapshot 1`] = ` +Object { + "detail": Array [ + Array [ + "signal", + "SIGYOLO", + ], + Array [ + "command", + "some command", + "a", + "r", + "g", + "s", + "https://evil:***@npmjs.org", + ], + Array [ + "", + "stdout", + ], + Array [ + "", + "stderr", + ], + ], + "summary": Array [ + Array [ + "", + "cmd err", + ], + ], +} +` + exports[`test/lib/utils/error-message.js TAP bad engine with config loaded > must match snapshot 1`] = ` Object { "detail": Array [ diff --git a/test/lib/utils/error-message.js b/test/lib/utils/error-message.js index d1c67a95137c4..6b2b5c9222e77 100644 --- a/test/lib/utils/error-message.js +++ b/test/lib/utils/error-message.js @@ -201,6 +201,17 @@ t.test('default message', t => { t.end() }) +t.test('args are cleaned', t => { + t.matchSnapshot(errorMessage(Object.assign(new Error('cmd err'), { + cmd: 'some command', + signal: 'SIGYOLO', + args: ['a', 'r', 'g', 's', 'https://evil:password@npmjs.org'], + stdout: 'stdout', + stderr: 'stderr', + }), npm)) + t.end() +}) + t.test('eacces/eperm', t => { const runTest = (windows, loaded, cachePath, cacheDest) => t => { if (windows)