inspector: log exceptions in message handlers
Fixes: https://github.com/nodejs/node/issues/14965 PR-URL: https://github.com/nodejs/node/pull/14980 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
This commit is contained in:
parent
7540821fb5
commit
9bae3eacc6
@ -29,14 +29,18 @@ class Session extends EventEmitter {
|
|||||||
|
|
||||||
[onMessageSymbol](message) {
|
[onMessageSymbol](message) {
|
||||||
const parsed = JSON.parse(message);
|
const parsed = JSON.parse(message);
|
||||||
if (parsed.id) {
|
try {
|
||||||
const callback = this[messageCallbacksSymbol].get(parsed.id);
|
if (parsed.id) {
|
||||||
this[messageCallbacksSymbol].delete(parsed.id);
|
const callback = this[messageCallbacksSymbol].get(parsed.id);
|
||||||
if (callback)
|
this[messageCallbacksSymbol].delete(parsed.id);
|
||||||
callback(parsed.error || null, parsed.result || null);
|
if (callback)
|
||||||
} else {
|
callback(parsed.error || null, parsed.result || null);
|
||||||
this.emit(parsed.method, parsed);
|
} else {
|
||||||
this.emit('inspectorNotification', parsed);
|
this.emit(parsed.method, parsed);
|
||||||
|
this.emit('inspectorNotification', parsed);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
process.emitWarning(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,14 +33,25 @@ function debuggerPausedCallback(session, notification) {
|
|||||||
checkScope(session, scopeId);
|
checkScope(session, scopeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNoCrashWithExceptionInCallback() {
|
function waitForWarningSkipAsyncStackTraces(resolve) {
|
||||||
|
process.once('warning', function(warning) {
|
||||||
|
if (warning.code === 'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE') {
|
||||||
|
waitForWarningSkipAsyncStackTraces(resolve);
|
||||||
|
} else {
|
||||||
|
resolve(warning);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testNoCrashWithExceptionInCallback() {
|
||||||
// There is a deliberate exception in the callback
|
// There is a deliberate exception in the callback
|
||||||
const session = new inspector.Session();
|
const session = new inspector.Session();
|
||||||
session.connect();
|
session.connect();
|
||||||
const error = new Error('We expect this');
|
const error = new Error('We expect this');
|
||||||
assert.throws(() => {
|
console.log('Expecting warning to be emitted');
|
||||||
session.post('Console.enable', () => { throw error; });
|
const promise = new Promise(waitForWarningSkipAsyncStackTraces);
|
||||||
}, (e) => e === error);
|
session.post('Console.enable', () => { throw error; });
|
||||||
|
assert.strictEqual(await promise, error);
|
||||||
session.disconnect();
|
session.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +108,33 @@ function testSampleDebugSession() {
|
|||||||
assert.throws(() => session.post('Debugger.enable'), (e) => !!e);
|
assert.throws(() => session.post('Debugger.enable'), (e) => !!e);
|
||||||
}
|
}
|
||||||
|
|
||||||
testNoCrashWithExceptionInCallback();
|
async function testNoCrashConsoleLogBeforeThrow() {
|
||||||
testSampleDebugSession();
|
const session = new inspector.Session();
|
||||||
let breakpointHit = false;
|
session.connect();
|
||||||
scopeCallback = () => (breakpointHit = true);
|
let attempt = 1;
|
||||||
debuggedFunction();
|
process.on('warning', common.mustCall(3));
|
||||||
assert.strictEqual(breakpointHit, false);
|
session.on('inspectorNotification', () => {
|
||||||
testSampleDebugSession();
|
if (attempt++ > 3)
|
||||||
|
return;
|
||||||
|
console.log('console.log in handler');
|
||||||
|
throw new Error('Exception in handler');
|
||||||
|
});
|
||||||
|
session.post('Runtime.enable');
|
||||||
|
console.log('Did not crash');
|
||||||
|
session.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
common.crashOnUnhandledRejection();
|
||||||
|
|
||||||
|
async function doTests() {
|
||||||
|
await testNoCrashWithExceptionInCallback();
|
||||||
|
testSampleDebugSession();
|
||||||
|
let breakpointHit = false;
|
||||||
|
scopeCallback = () => (breakpointHit = true);
|
||||||
|
debuggedFunction();
|
||||||
|
assert.strictEqual(breakpointHit, false);
|
||||||
|
testSampleDebugSession();
|
||||||
|
await testNoCrashConsoleLogBeforeThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
doTests();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user