From 31bc3c12b5f17c89cae8ce5c1c8f6380a12ed789 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 26 Jul 2017 22:41:06 -0700 Subject: [PATCH] test: improve error logging for inspector test If JSON.parse() fails, print a message showing the JSON that failed to parse. This is to help with debugging a current test failure on CI. Refs: https://github.com/nodejs/node/issues/14507 --- test/inspector/inspector-helper.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index c05212b193d7a1..35f23dfeb5cba6 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -73,8 +73,15 @@ function parseWSFrame(buffer, handler) { } if (buffer.length < bodyOffset + dataLen) return 0; - const message = JSON.parse( - buffer.slice(bodyOffset, bodyOffset + dataLen).toString('utf8')); + const jsonPayload = + buffer.slice(bodyOffset, bodyOffset + dataLen).toString('utf8'); + let message; + try { + message = JSON.parse(jsonPayload); + } catch (e) { + console.error(`JSON.parse() failed for: ${jsonPayload}`); + throw e; + } if (DEBUG) console.log('[received]', JSON.stringify(message)); handler(message);