Skip to content

Commit b0c310d

Browse 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 <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 0034820 commit b0c310d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/inspector.js

+9-2
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);

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

+11-6
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)