Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send json errors to stderr, not stdout #2155

Closed
wants to merge 1 commit into from
Closed
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
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