diff --git a/lib/inspector.js b/lib/inspector.js index cc8f86ee46c7c3..43cdd53bf0a4b8 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -3,6 +3,7 @@ const { ERR_INSPECTOR_ALREADY_CONNECTED, ERR_INSPECTOR_CLOSED, + ERR_INSPECTOR_COMMAND, ERR_INSPECTOR_NOT_AVAILABLE, ERR_INSPECTOR_NOT_CONNECTED, ERR_INVALID_ARG_TYPE, @@ -48,8 +49,14 @@ class Session extends EventEmitter { if (parsed.id) { const callback = this[messageCallbacksSymbol].get(parsed.id); this[messageCallbacksSymbol].delete(parsed.id); - if (callback) - callback(parsed.error || null, parsed.result || null); + if (callback) { + if (parsed.error) { + return callback(new ERR_INSPECTOR_COMMAND(parsed.error.code, + parsed.error.message)); + } + + callback(null, parsed.result); + } } else { this.emit(parsed.method, parsed); this.emit('inspectorNotification', parsed); diff --git a/test/sequential/test-inspector-runtime-evaluate-with-timeout.js b/test/sequential/test-inspector-runtime-evaluate-with-timeout.js index 1def39a82fead4..79c746540bda5b 100644 --- a/test/sequential/test-inspector-runtime-evaluate-with-timeout.js +++ b/test/sequential/test-inspector-runtime-evaluate-with-timeout.js @@ -5,17 +5,22 @@ const common = require('../common'); common.skipIfInspectorDisabled(); (async function test() { - const { strictEqual } = require('assert'); + const assert = require('assert'); const { Session } = require('inspector'); const { promisify } = require('util'); const session = new Session(); session.connect(); session.post = promisify(session.post); - const result = await session.post('Runtime.evaluate', { - expression: 'for(;;);', - timeout: 0 - }).catch((e) => e); - strictEqual(result.message, 'Execution was terminated'); + await assert.rejects( + session.post('Runtime.evaluate', { + expression: 'for(;;);', + timeout: 0 + }), + { + code: 'ERR_INSPECTOR_COMMAND', + message: 'Inspector error -32000: Execution was terminated' + } + ); session.disconnect(); })();