Browse Source

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>
v6.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
1a88c3e5f6
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 11
      test/inspector/inspector-helper.js

11
test/inspector/inspector-helper.js

@ -64,8 +64,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);

Loading…
Cancel
Save