Skip to content

Commit

Permalink
send json errors to stderr, not stdout
Browse files Browse the repository at this point in the history
Fixes: #2150
  • Loading branch information
isaacs committed Nov 11, 2020
1 parent a28aff7 commit f0700d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/utils/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const errorHandler = (er) => {
detail: messageText(msg.detail),
},
}
console.log(JSON.stringify(error, null, 2))
console.error(JSON.stringify(error, null, 2))
}

exit(typeof er.errno === 'number' ? er.errno : typeof er.code === 'number' ? er.code : 1)
Expand Down
6 changes: 3 additions & 3 deletions test/lib/utils/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ t.test('console.log output using --json', (t) => {

config.values.json = true

const _log = console.log
console.log = (jsonOutput) => {
const _error = console.error
console.error = (jsonOutput) => {
t.deepEqual(
JSON.parse(jsonOutput),
{
Expand All @@ -236,7 +236,7 @@ t.test('console.log output using --json', (t) => {
errorHandler(new Error('Error: EBADTHING Something happened'))

t.teardown(() => {
console.log = _log
console.error = _error
delete config.values.json
})
})
Expand Down

0 comments on commit f0700d9

Please sign in to comment.