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 aa24681

Browse filesBrowse files
addaleaxtargos
authored andcommitted
repl: display prompt once after error callback
Do not call `.displayPrompt()` twice after the `eval` callback resulted in an error. (This does not affect the default eval because it doesn’t use the callback if an error occurs.) PR-URL: #38314 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 30de036 commit aa24681
Copy full SHA for aa24681

File tree

Expand file treeCollapse file tree

2 files changed

+28
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-2
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,11 @@ function REPLServer(prompt,
889889
self.output.write(self.writer(ret) + '\n');
890890
}
891891

892-
// Display prompt again
893-
self.displayPrompt();
892+
// Display prompt again (unless we already did by emitting the 'error'
893+
// event on the domain instance).
894+
if (!e) {
895+
self.displayPrompt();
896+
}
894897
}
895898
});
896899

Collapse file
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const repl = require('repl');
5+
const { PassThrough } = require('stream');
6+
const input = new PassThrough();
7+
const output = new PassThrough();
8+
9+
const r = repl.start({
10+
input, output,
11+
eval: common.mustCall((code, context, filename, cb) => {
12+
r.setPrompt('prompt! ');
13+
cb(new Error('err'));
14+
})
15+
});
16+
17+
input.end('foo\n');
18+
19+
// The output includes exactly one post-error prompt.
20+
const out = output.read().toString();
21+
assert.match(out, /prompt!/);
22+
assert.doesNotMatch(out, /prompt![\S\s]*prompt!/);
23+
output.on('data', common.mustNotCall());

0 commit comments

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