diff options
author | Rich Trott <rtrott@gmail.com> | 2017-07-26 22:41:06 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-07-28 19:40:07 -0700 |
commit | bfb4f4224d9f8f87944d611dd569d1d3579f5523 (patch) | |
tree | 3155d8fc9db9e865d7bf35932fc689947270a7c9 | |
parent | 7128e3c117884ab8a611e0c63c0bbc9a547b51ba (diff) | |
download | android-node-v8-bfb4f4224d9f8f87944d611dd569d1d3579f5523.tar.gz android-node-v8-bfb4f4224d9f8f87944d611dd569d1d3579f5523.tar.bz2 android-node-v8-bfb4f4224d9f8f87944d611dd569d1d3579f5523.zip |
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.
PR-URL: https://github.com/nodejs/node/pull/14508
Ref: https://github.com/nodejs/node/issues/14507
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
-rw-r--r-- | test/inspector/inspector-helper.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index c05212b193..35f23dfeb5 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); |