From 1dbf0f9bb26ba70f4c6d0a807701d7652c31d7d4 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 10 Nov 2020 17:15:54 -0800 Subject: [PATCH] send json errors to stderr, not stdout Fixes: #2150 Credit: @isaacs Close: #2155 Reviewed-by: @ruyadorno --- lib/utils/error-handler.js | 2 +- test/lib/utils/error-handler.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js index dc9e2a26bcfa5..476ca9e917b36 100644 --- a/lib/utils/error-handler.js +++ b/lib/utils/error-handler.js @@ -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) diff --git a/test/lib/utils/error-handler.js b/test/lib/utils/error-handler.js index 840b3a3565031..9e32dfc5ff8db 100644 --- a/test/lib/utils/error-handler.js +++ b/test/lib/utils/error-handler.js @@ -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), { @@ -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 }) })