Skip to content

Commit cbb92b0

Browse files
authored
debugger: throw a more useful error when the frame is missing
PR-URL: #42776 Fixes: #42775 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 40162db commit cbb92b0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/internal/debugger/inspect_repl.js

+3
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@ function createRepl(inspector) {
681681

682682
// List source code
683683
function list(delta = 5) {
684+
if (!selectedFrame) {
685+
throw new ERR_DEBUGGER_ERROR('Requires execution to be paused');
686+
}
684687
return selectedFrame.list(delta).then(null, (error) => {
685688
print("You can't list source code right now");
686689
throw error;

test/sequential/test-debugger-list.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
common.skipIfInspectorDisabled();
5+
6+
const fixtures = require('../common/fixtures');
7+
const startCLI = require('../common/debugger');
8+
9+
const assert = require('assert');
10+
11+
const cli = startCLI([fixtures.path('debugger/three-lines.js')]);
12+
13+
(async () => {
14+
await cli.waitForInitialBreak();
15+
await cli.waitForPrompt();
16+
await cli.command('list(0)');
17+
assert.match(cli.output, /> 1 let x = 1;/);
18+
await cli.command('list(1)');
19+
assert.match(cli.output, /> 1 let x = 1;\r?\n {2}2 x = x \+ 1;/);
20+
await cli.command('list(10)');
21+
assert.match(cli.output, /> 1 let x = 1;\r?\n {2}2 x = x \+ 1;\r?\n {2}3 module\.exports = x;\r?\n {2}4 /);
22+
await cli.command('c');
23+
await cli.waitFor(/disconnect/);
24+
await cli.waitFor(/debug> $/);
25+
await cli.command('list()');
26+
await cli.waitFor(/ERR_DEBUGGER_ERROR/);
27+
assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/);
28+
})()
29+
.finally(() => cli.quit())
30+
.then(common.mustCall());

0 commit comments

Comments
 (0)