diff --git a/doc/api/errors.md b/doc/api/errors.md index ca2beef2dd5fd6..b9d26421497fde 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1159,6 +1159,11 @@ inspector was already connected. While using the `inspector` module, an attempt was made to use the inspector after the session had already closed. + +### ERR_INSPECTOR_COMMAND + +An error occurred while issuing a command via the `inspector` module. + ### ERR_INSPECTOR_NOT_AVAILABLE 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/lib/internal/errors.js b/lib/internal/errors.js index 13a6194d0cb016..b3b745252a195d 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -706,6 +706,7 @@ E('ERR_INCOMPATIBLE_OPTION_PAIR', 'Option "%s" can not be used in combination with option "%s"', TypeError); E('ERR_INSPECTOR_ALREADY_CONNECTED', '%s is already connected', Error); E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error); +E('ERR_INSPECTOR_COMMAND', 'Inspector error %d: %s', Error); E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available', Error); E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected', Error); E('ERR_INVALID_ADDRESS_FAMILY', 'Invalid address family: %s', RangeError); 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(); })();