Skip to content

Commit 1dbf0f9

Browse files
committed
send json errors to stderr, not stdout
Fixes: #2150 Credit: @isaacs Close: #2155 Reviewed-by: @ruyadorno
1 parent fd1d7a2 commit 1dbf0f9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/utils/error-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const errorHandler = (er) => {
182182
detail: messageText(msg.detail),
183183
},
184184
}
185-
console.log(JSON.stringify(error, null, 2))
185+
console.error(JSON.stringify(error, null, 2))
186186
}
187187

188188
exit(typeof er.errno === 'number' ? er.errno : typeof er.code === 'number' ? er.code : 1)

test/lib/utils/error-handler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ t.test('console.log output using --json', (t) => {
218218

219219
config.values.json = true
220220

221-
const _log = console.log
222-
console.log = (jsonOutput) => {
221+
const _error = console.error
222+
console.error = (jsonOutput) => {
223223
t.deepEqual(
224224
JSON.parse(jsonOutput),
225225
{
@@ -236,7 +236,7 @@ t.test('console.log output using --json', (t) => {
236236
errorHandler(new Error('Error: EBADTHING Something happened'))
237237

238238
t.teardown(() => {
239-
console.log = _log
239+
console.error = _error
240240
delete config.values.json
241241
})
242242
})

0 commit comments

Comments
 (0)