Skip to content

module: improve error message from asynchronicity in require(esm) - #57126

Closed
joyeecheung wants to merge 2 commits into
nodejs:mainfrom
joyeecheung:module-race-message
Closed

module: improve error message from asynchronicity in require(esm)#57126
joyeecheung wants to merge 2 commits into
nodejs:mainfrom
joyeecheung:module-race-message

Conversation

@joyeecheung

Copy link
Copy Markdown
Member
  • Improve the error message that shows up when there is a race from doing require(esm) and import(esm) at the same time.
  • Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing parent and target file names, if available.

Drive-by: split the require(tla) tests since we are modifying the tests already.

Refs: https://github.com/fisker/prettier-issue-17139

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 18, 2025
Comment threadlib/internal/modules/esm/loader.js Outdated

@joyeecheungjoyeecheungFeb 18, 2025

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I can hit this branch via https://github.com/fisker/prettier-issue-17139 though I don't think it's reliably testable because it comes down to a race. From prettier/prettier#17139 it seems tiny changes to the module graph can make the race disappear. So it's probably not worth adding to the test suite in case this becomes a flaky test.

@joyeecheungjoyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecovBot commented Feb 18, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 79.62963% with 11 lines in your changes missing coverage. Please review.

Project coverage is 89.03%. Comparing base (2086877) to head (f2d314b).
Report is 13 commits behind head on main.

Files with missing linesPatch %Lines
lib/internal/modules/esm/loader.js57.14%9 Missing ⚠️
src/node_errors.h85.71%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #57126 +/- ##
==========================================
+ Coverage 89.02% 89.03% +0.01% 
==========================================
Files 665 665 Lines 193408 193451 +43 Branches 37283 37284 +1 ==========================================
+ Hits 172185 172243 +58 - Misses 13882 13897 +15 + Partials 7341 7311 -30 
Files with missing linesCoverage Δ
lib/internal/errors.js97.47% <100.00%> (+0.01%)⬆️
lib/internal/modules/esm/module_job.js99.26% <100.00%> (+<0.01%)⬆️
src/module_wrap.cc75.76% <100.00%> (ø)
src/node_errors.h85.29% <85.71%> (+0.29%)⬆️
lib/internal/modules/esm/loader.js97.01% <57.14%> (-0.86%)⬇️

... and 38 files with indirect coverage changes

If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
@joyeecheung

Copy link
Copy Markdown
MemberAuthor

Looks like the THROW_ERR_* and ERR_* macros are not prepared for a single string message that might contain characters that would otherwise need escaping if used as the format string. Added a special case in the macros to deal with it (I suspect this is not the only place that can e.g. pass a path into the error message formatter which might contain %, though we might have been getting away with it if the test cases did not happen to test on those errors...)

@joyeecheungjoyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@joyeecheungjoyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Feb 20, 2025
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 20, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 305d15a...8d10bc7

nodejs-github-bot pushed a commit that referenced this pull request Feb 20, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: #57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
nodejs-github-bot pushed a commit that referenced this pull request Feb 20, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Apr 17, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
@joyeecheungjoyeecheung mentioned this pull request Jul 13, 2025
9 tasks
joyeecheung added a commit to joyeecheung/node that referenced this pull request Aug 8, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: nodejs#57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
joyeecheung added a commit to joyeecheung/node that referenced this pull request Aug 8, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: nodejs#57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
marco-ippolito pushed a commit to joyeecheung/node that referenced this pull request Aug 20, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: nodejs#57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
marco-ippolito pushed a commit to joyeecheung/node that referenced this pull request Aug 20, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: nodejs#57126
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Aug 20, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 20, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 23, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 23, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 25, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 27, 2025
If the macros are used as ERR_*(isolate, message) or
THROW_ERR_*(isolate, message) with a single string argument, do run
formatter on the message, and allow the caller to pass in a message
directly with characters that would otherwise need escaping if used
as format string unconditionally.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
marco-ippolito pushed a commit that referenced this pull request Aug 27, 2025
- Improve the error message that shows up when there is a race
from doing require(esm) and import(esm) at the same time.
- Improve error message of ERR_REQUIRE_ASYNC_MODULE by showing
parent and target file names, if available.
Drive-by: split the require(tla) tests since we are modifying
the tests already.
PR-URL: #57126
Backport-PR-URL: #59504
Refs: https://github.com/fisker/prettier-issue-17139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Refs: #52697
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.commit-queue-rebaseAdd this label to allow the Commit Queue to land a PR in several commits.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@joyeecheung@nodejs-github-bot@jasnell@legendecas@aduh95