Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: display prompt once after error callback #38314

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
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());