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: don't use deprecated domain module #55204

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

Conversation

RedYetiDev
Copy link
Member

@RedYetiDev RedYetiDev commented Oct 1, 2024

This PR refactors the REPL module by eliminating the deprecated node:domain module. It replaces its functionality with a modern approach using a try/catch block and process.setUncaughtExceptionCaptureCallback.

Why?

The domain module has been deprecated for a while, and its use is discouraged. Despite this, Node.js still relies on it in a key component: the REPL. To lead by example and promote best practices, this PR updates the REPL module to use more up-to-date error-handling mechanisms, completely removing reliance on the deprecated domain module.

Additionally, this update simplifies the REPL's code and results in a slight performance improvement—though the gains are give-or-take a few ticks and may not be noticeable.

Breaking Changes

This PR is marked as semver-major because it introduces functional changes to the REPL:

  • Removal of options.domain: This undocumented feature is removed (without a formal deprecation cycle, given the domain module itself is deprecated, and the feature was never documented nor tested).
  • REPL's inspect no longer captures just-resolved promise prototype symbols: (IIUC) The symbols (e.g. async ids) are not applied in the same event loop tick as the promise resolution. Since the new implementation is faster, it inspects the promise before the symbols are added.
  • uncaughtException listeners, while ingored, are no longer restricted from use. Along with this, ERR_INVALID_REPL_INPUT is no longer required, and has been removed.

This PR is also marked needs-citgm in case any of the above cause breakages.


CC @nodejs/repl
CC @nodejs/tsc due to the semver-major

@RedYetiDev RedYetiDev added the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 1, 2024
@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Oct 1, 2024
@RedYetiDev RedYetiDev added the needs-citgm PRs that need a CITGM CI run. label Oct 1, 2024
@RedYetiDev RedYetiDev marked this pull request as draft October 1, 2024 00:33
@RedYetiDev

This comment was marked as resolved.

@RedYetiDev RedYetiDev marked this pull request as ready for review October 1, 2024 00:34
@@ -151,34 +151,18 @@ global or scoped variable, the input `fs` will be evaluated on-demand as

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/55204
description: The `process.setUncaughtExceptionCaptureCallback()`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an implementation detail. Does it change the behavior of the function? If not, we should remove it from here. If it changes the behavior, this description should mention the behavior change rather than implementation specifics.

}

domainSet.add(this._domain);
process.setUncaughtExceptionCaptureCallback(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we call it twice? Please add a comment

@@ -34,13 +34,6 @@ const works = [['inner.one'], 'inner.o'];
const putIn = new ArrayStream();
const testMe = repl.start('', putIn);

// Some errors might be passed to the domain.
testMe._domain.on('error', function(reason) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require CITGM since you're altering a publicly accessible variable.

assert.ok(result.status, 'testFile swallowed its error');
const err = result.stderr.toString();
assert.ok(err.includes('fhqwhgads'), err);
assert.ok(result.stdout.toString().includes('fhqwhgads'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this test?

@@ -11,8 +11,6 @@ const testMe = repl.start('', putIn, function(cmd, context, filename,
callback(null, cmd);
});

testMe._domain.on('error', common.mustNotCall());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an equivalent change.

@@ -174,7 +174,7 @@ async function ordinaryTests() {
'undefined',
]],
// Regression test for https://github.com/nodejs/node/issues/43777.
['await Promise.resolve(123), Promise.resolve(456)', 'Promise {', { line: 0 }],
['await Promise.resolve(123), Promise.resolve(456)', 'Promise { 456 }', { line: 0 }],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changed?

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.34%. Comparing base (89a2f56) to head (42e6441).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55204      +/-   ##
==========================================
- Coverage   88.39%   88.34%   -0.06%     
==========================================
  Files         652      650       -2     
  Lines      186565   186008     -557     
  Branches    36046    35885     -161     
==========================================
- Hits       164916   164325     -591     
- Misses      14908    15016     +108     
+ Partials     6741     6667      -74     
Files with missing lines Coverage Δ
lib/internal/errors.js 96.93% <ø> (-0.06%) ⬇️
lib/repl.js 94.79% <100.00%> (-0.08%) ⬇️

... and 44 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. needs-ci PRs that need a full CI run. needs-citgm PRs that need a CITGM CI run. repl Issues and PRs related to the REPL subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants