Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

islandryu
Copy link
Member

No description provided.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Jul 13, 2025
@islandryu islandryu marked this pull request as draft July 13, 2025 07:13
Copy link

codecov bot commented Jul 13, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.07%. Comparing base (b16a0e7) to head (11222b5).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/repl.js 91.66% 1 Missing ⚠️
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     
Files with missing lines Coverage Δ
lib/repl.js 94.24% <91.66%> (+0.02%) ⬆️

... and 45 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@islandryu islandryu force-pushed the fix/repl-complete-getter-error branch 2 times, most recently from 7852293 to eacb7f6 Compare July 13, 2025 08:12
@islandryu islandryu marked this pull request as ready for review July 13, 2025 08:13
@islandryu
Copy link
Member Author

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.
#58943

@dario-piotrowicz
I'd appreciate it if you could take a look.

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a 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 😄

@islandryu
Copy link
Member Author

Thanks for the feedback!
Indeed, my test was unnecessarily complex.
I've updated it following your suggestion!

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a 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! 🚀

@islandryu islandryu added request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jul 13, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 15, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@islandryu islandryu force-pushed the fix/repl-complete-getter-error branch from a12247b to 11222b5 Compare July 18, 2025 06:31
@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants