Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const errorMessage = (er, npm) => {
default:
summary.push(['', er.message || er])
if (er.cause) {
detail.push(['cause', er.cause.message])
detail.push(['cause', replaceInfo(er.cause.message)])
}
if (er.signal) {
detail.push(['signal', er.signal])
Expand All @@ -356,10 +356,10 @@ const errorMessage = (er, npm) => {
detail.push(['command', ...[er.cmd, ...er.args.map(replaceInfo)]])
}
if (er.stdout) {
detail.push(['', er.stdout.trim()])
detail.push(['', replaceInfo(er.stdout.trim())])
}
if (er.stderr) {
detail.push(['', er.stderr.trim()])
detail.push(['', replaceInfo(er.stderr.trim())])
}
break
}
Expand Down
16 changes: 16 additions & 0 deletions test/lib/utils/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ t.test('args are cleaned', async t => {
})))
})

t.test('cause, stdout and stderr are cleaned', async t => {
const { errorMessage } = await loadMockNpm(t)
const { detail } = errorMessage(Object.assign(new Error('cmd err'), {
cmd: 'some command',
signal: 'SIGYOLO',
args: ['a', 'r', 'g', 's'],
cause: new Error('fetch failed for https://user:sekrit@registry.example.com/foo'),
stdout: 'log line with a token npm_0123456789abcdef0123456789abcdef0123\n',
stderr: 'git error for https://user:sekrit@github.com/foo/bar.git\n',
}))
const flat = JSON.stringify(detail)
t.notMatch(flat, /sekrit/)
t.notMatch(flat, /npm_0123456789/)
t.match(flat, /registry\.example\.com/, 'cause keeps the non secret part of the url')
})

t.test('eacces/eperm', async t => {
const runTest = (windows, loaded, cachePath, cacheDest) => async t => {
const { errorMessage, logs, cache } = await loadMockNpm(t, {
Expand Down