Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b0c310d

Browse filesBrowse files
cjihrigaddaleax
authored andcommitted
inspector: return Error objects on error
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>
1 parent 0034820 commit b0c310d
Copy full SHA for b0c310d

File tree

Expand file treeCollapse file tree

2 files changed

+20
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-8
lines changed
Open diff view settings
Collapse file

‎lib/inspector.js‎

Copy file name to clipboardExpand all lines: lib/inspector.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const {
44
ERR_INSPECTOR_ALREADY_CONNECTED,
55
ERR_INSPECTOR_CLOSED,
6+
ERR_INSPECTOR_COMMAND,
67
ERR_INSPECTOR_NOT_AVAILABLE,
78
ERR_INSPECTOR_NOT_CONNECTED,
89
ERR_INVALID_ARG_TYPE,
@@ -48,8 +49,14 @@ class Session extends EventEmitter {
4849
if (parsed.id) {
4950
const callback = this[messageCallbacksSymbol].get(parsed.id);
5051
this[messageCallbacksSymbol].delete(parsed.id);
51-
if (callback)
52-
callback(parsed.error || null, parsed.result || null);
52+
if (callback) {
53+
if (parsed.error) {
54+
return callback(new ERR_INSPECTOR_COMMAND(parsed.error.code,
55+
parsed.error.message));
56+
}
57+
58+
callback(null, parsed.result);
59+
}
5360
} else {
5461
this.emit(parsed.method, parsed);
5562
this.emit('inspectorNotification', parsed);
Collapse file

‎test/sequential/test-inspector-runtime-evaluate-with-timeout.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-inspector-runtime-evaluate-with-timeout.js
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ const common = require('../common');
55
common.skipIfInspectorDisabled();
66

77
(async function test() {
8-
const { strictEqual } = require('assert');
8+
const assert = require('assert');
99
const { Session } = require('inspector');
1010
const { promisify } = require('util');
1111

1212
const session = new Session();
1313
session.connect();
1414
session.post = promisify(session.post);
15-
const result = await session.post('Runtime.evaluate', {
16-
expression: 'for(;;);',
17-
timeout: 0
18-
}).catch((e) => e);
19-
strictEqual(result.message, 'Execution was terminated');
15+
await assert.rejects(
16+
session.post('Runtime.evaluate', {
17+
expression: 'for(;;);',
18+
timeout: 0
19+
}),
20+
{
21+
code: 'ERR_INSPECTOR_COMMAND',
22+
message: 'Inspector error -32000: Execution was terminated'
23+
}
24+
);
2025
session.disconnect();
2126
})();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.