Skip to content

Commit

Permalink
debugger: throw debugger error when the frame is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
cola119 committed Apr 20, 2022
1 parent b008e96 commit cd64887
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ function createRepl(inspector) {

// List source code
function list(delta = 5) {
if (!selectedFrame) {
throw new ERR_DEBUGGER_ERROR('Requires execution to be paused');
}
return selectedFrame.list(delta).then(null, (error) => {
print("You can't list source code right now");
throw error;
Expand Down
35 changes: 35 additions & 0 deletions test/sequential/test-debugger-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
const common = require('../common');

common.skipIfInspectorDisabled();

const fixtures = require('../common/fixtures');
const startCLI = require('../common/debugger');

const assert = require('assert');

const cli = startCLI([fixtures.path('debugger/three-lines.js')]);

cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('list(0)'))
.then(() => {
assert.match(cli.output, /> 1 let x = 1;/);
})
.then(() => cli.command('list(1)'))
.then(() => {
assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;/);
})
.then(() => cli.command('list(10)'))
.then(() => {
assert.match(cli.output, /> 1 let x = 1;\n {2}2 x = x \+ 1;\n {2}3 module\.exports = x;\n {2}4 /);
})
.then(() => cli.command('c'))
.then(() => cli.waitFor(/disconnect/))
.then(() => cli.waitForPrompt())
.then(() => cli.command('list()'))
.then(() => {
assert.match(cli.output, /Uncaught Error \[ERR_DEBUGGER_ERROR\]: Requires execution to be paused/);
})
.finally(() => cli.quit())
.then(common.mustCall());

0 comments on commit cd64887

Please sign in to comment.