Skip to content

Commit

Permalink
fix(logs): clean args for failed commands
Browse files Browse the repository at this point in the history
PR-URL: #3761
Credit: @wraithgar
Close: #3761
Reviewed-by: @lukekarrys
  • Loading branch information
wraithgar committed Sep 15, 2021
1 parent 371655a commit ca792ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand Down
34 changes: 34 additions & 0 deletions tap-snapshots/test/lib/utils/error-message.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
11 changes: 11 additions & 0 deletions test/lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ca792ac

Please sign in to comment.