-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
repl: handle errors from getters during completion #59044
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #59044 +/- ##
==========================================
+ Coverage 90.05% 90.07% +0.01%
==========================================
Files 645 645
Lines 189153 189162 +9
Branches 37091 37099 +8
==========================================
+ Hits 170348 170380 +32
+ Misses 11528 11478 -50
- Partials 7277 7304 +27
🚀 New features to boost your workflow:
|
7852293
to
eacb7f6
Compare
I noticed this while trying to add a test for a getter in the following PR, it seems that if an error is thrown inside a getter, the server itself crashes. @dario-piotrowicz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@islandryu thanks so much for spotting the issue 🙏
The change looks good to me 😃
But I think the test can be cleaned up a bit (it looks more complex than it needs to me in my opinion), in it I see:
- the unnecessary definition of a class
- unnecessary multiple evals
- missing spacing
- duplicated code
I would suggest to change the test to something like the following instead:
'use strict';
const common = require('../common');
const repl = require('repl');
const ArrayStream = require('../common/arraystream');
const assert = require('assert');
(async function() {
await runTest();
})().then(common.mustCall());
async function runTest() {
const input = new ArrayStream();
const output = new ArrayStream();
const replServer = repl.start({
prompt: '',
input,
output: output,
allowBlockingCompletions: true,
terminal: true
});
replServer._domain.on('error', (e) => {
assert.fail(`Error in REPL domain: ${e}`);
});
await new Promise((resolve, reject) => {
replServer.eval(`
const getNameText = () => "name";
const foo = { get name() { throw new Error(); } };
`, replServer.context, '', (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
['foo.name.', 'foo["name"].', 'foo[getNameText()].'].forEach(test => {
replServer.complete(
test,
common.mustCall((error, data) => {
assert.strictEqual(error, null);
assert.strictEqual(data.length, 2);
assert.strictEqual(data[1], test);
})
);
})
}
But besides the test the change looks great to me 😄
Thanks for the feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for updating the test @islandryu 🫶
Looks good to me, again thanks a lot for spotting this! 🚀
a12247b
to
11222b5
Compare
No description provided.