Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspector: return Error objects on error #26255

Merged
merged 2 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<a id="ERR_INSPECTOR_COMMAND"></a>
### ERR_INSPECTOR_COMMAND

An error occurred while issuing a command via the `inspector` module.

<a id="ERR_INSPECTOR_NOT_AVAILABLE"></a>
### ERR_INSPECTOR_NOT_AVAILABLE

Expand Down
11 changes: 9 additions & 2 deletions lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 11 additions & 6 deletions test/sequential/test-inspector-runtime-evaluate-with-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})();