Skip to content

Commit ca792ac

Browse files
committed
fix(logs): clean args for failed commands
PR-URL: #3761 Credit: @wraithgar Close: #3761 Reviewed-by: @lukekarrys
1 parent 371655a commit ca792ac

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

lib/utils/error-message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ module.exports = (er, npm) => {
367367
detail.push(['signal', er.signal])
368368

369369
if (er.cmd && Array.isArray(er.args))
370-
detail.push(['command', ...[er.cmd, ...er.args]])
370+
detail.push(['command', ...[er.cmd, ...er.args.map(replaceInfo)]])
371371

372372
if (er.stdout)
373373
detail.push(['', er.stdout.trim()])

tap-snapshots/test/lib/utils/error-message.js.test.cjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,40 @@ Object {
180180
}
181181
`
182182

183+
exports[`test/lib/utils/error-message.js TAP args are cleaned > must match snapshot 1`] = `
184+
Object {
185+
"detail": Array [
186+
Array [
187+
"signal",
188+
"SIGYOLO",
189+
],
190+
Array [
191+
"command",
192+
"some command",
193+
"a",
194+
"r",
195+
"g",
196+
"s",
197+
"https://evil:***@npmjs.org",
198+
],
199+
Array [
200+
"",
201+
"stdout",
202+
],
203+
Array [
204+
"",
205+
"stderr",
206+
],
207+
],
208+
"summary": Array [
209+
Array [
210+
"",
211+
"cmd err",
212+
],
213+
],
214+
}
215+
`
216+
183217
exports[`test/lib/utils/error-message.js TAP bad engine with config loaded > must match snapshot 1`] = `
184218
Object {
185219
"detail": Array [

test/lib/utils/error-message.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ t.test('default message', t => {
201201
t.end()
202202
})
203203

204+
t.test('args are cleaned', t => {
205+
t.matchSnapshot(errorMessage(Object.assign(new Error('cmd err'), {
206+
cmd: 'some command',
207+
signal: 'SIGYOLO',
208+
args: ['a', 'r', 'g', 's', 'https://evil:[email protected]'],
209+
stdout: 'stdout',
210+
stderr: 'stderr',
211+
}), npm))
212+
t.end()
213+
})
214+
204215
t.test('eacces/eperm', t => {
205216
const runTest = (windows, loaded, cachePath, cacheDest) => t => {
206217
if (windows)

0 commit comments

Comments
 (0)