Skip to content

Commit a4eb557

Browse 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 c9ce98c commit a4eb557

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lib/repl.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,11 @@ function REPLServer(prompt,
861861
self.output.write(self.writer(ret) + '\n');
862862
}
863863

864-
// Display prompt again
865-
self.displayPrompt();
864+
// Display prompt again (unless we already did by emitting the 'error'
865+
// event on the domain instance).
866+
if (!e) {
867+
self.displayPrompt();
868+
}
866869
}
867870
});
868871

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)