Skip to content

Commit

Permalink
inspector: return Error objects on error
Browse files Browse the repository at this point in the history
The inspector communicates errors via POJOs. This commit
wraps the error information in an actual Error object.

PR-URL: #26255
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
cjihrig committed Feb 26, 2019
1 parent d7a3c3c commit e3d4a7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
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
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();
})();

0 comments on commit e3d4a7d

Please sign in to comment.