Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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>
  • Loading branch information
addaleax committed Apr 22, 2021
commit 9f5977a74d99d9caa5361220eaf3d6189e400b0a
7 changes: 5 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,11 @@ function REPLServer(prompt,
self.output.write(self.writer(ret) + '\n');
}

// Display prompt again
self.displayPrompt();
// Display prompt again (unless we already did by emitting the 'error'
// event on the domain instance).
if (!e) {
self.displayPrompt();
}
}
});

Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-repl-uncaught-exception-evalcallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
const { PassThrough } = require('stream');
const input = new PassThrough();
const output = new PassThrough();

const r = repl.start({
input, output,
eval: common.mustCall((code, context, filename, cb) => {
r.setPrompt('prompt! ');
cb(new Error('err'));
})
});

input.end('foo\n');

// The output includes exactly one post-error prompt.
const out = output.read().toString();
assert.match(out, /prompt!/);
assert.doesNotMatch(out, /prompt![\S\s]*prompt!/);
output.on('data', common.mustNotCall());