diff --git a/lib/repl.js b/lib/repl.js index 40d585af526ffd..1ec438e5210e49 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -861,8 +861,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(); + } } }); diff --git a/test/parallel/test-repl-uncaught-exception-evalcallback.js b/test/parallel/test-repl-uncaught-exception-evalcallback.js new file mode 100644 index 00000000000000..a6f6e341049d6c --- /dev/null +++ b/test/parallel/test-repl-uncaught-exception-evalcallback.js @@ -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());