Skip to content

module: avoid throwing when findPackageJSON is called on nonexistent - #55822

Closed
JakobJingleheimer wants to merge 1 commit into
nodejs:mainfrom
JakobJingleheimer:fix/find-pjson-invalid-arg-on-unfound
Closed

module: avoid throwing when findPackageJSON is called on nonexistent#55822
JakobJingleheimer wants to merge 1 commit into
nodejs:mainfrom
JakobJingleheimer:fix/find-pjson-invalid-arg-on-unfound

Conversation

@JakobJingleheimer

@JakobJingleheimerJakobJingleheimer commented Nov 11, 2024

Copy link
Copy Markdown
Member

The edge-case occurs when ESMLoader can't resolve the target.

The documented behaviour is already for it to return undefined, so this fixes a small bug.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-botnodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Nov 11, 2024
@JakobJingleheimer
JakobJingleheimerforce-pushed the fix/find-pjson-invalid-arg-on-unfound branch from de8448a to b923210CompareNovember 11, 2024 21:34
@aduh95

Copy link
Copy Markdown
Contributor

The commit message guidelines stipulates that the word after the subsystem needs to be an imperative verb, could you amend it please?

@JakobJingleheimer
JakobJingleheimerforce-pushed the fix/find-pjson-invalid-arg-on-unfound branch from b923210 to a565f22CompareNovember 11, 2024 21:41
@JakobJingleheimerJakobJingleheimer changed the title module: findPackageJSON avoid ERR_INVALID_ARG_TYPE when unfoundmodule: avoid ERR_INVALID_ARG_TYPE when findPackageJSON is stumpedNov 11, 2024
@JakobJingleheimer

Copy link
Copy Markdown
MemberAuthor

@aduh95 the character limit makes this quite a challenge 😅

@aduh95

Copy link
Copy Markdown
Contributor

Here's a suggestion: module: avoid throwing when `findPackageJSON` is called on inexistant

@JakobJingleheimer
JakobJingleheimerforce-pushed the fix/find-pjson-invalid-arg-on-unfound branch from a565f22 to c02aebcCompareNovember 11, 2024 22:38
@JakobJingleheimerJakobJingleheimer changed the title module: avoid ERR_INVALID_ARG_TYPE when findPackageJSON is stumpedmodule: avoid throwing when findPackageJSON is called on nonexistentNov 11, 2024

@anonriganonrig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test?

@codecov

codecovBot commented Nov 11, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.41%. Comparing base (32ff100) to head (c02aebc).
Report is 355 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #55822 +/- ##
==========================================
+ Coverage 88.39% 88.41% +0.01% 
==========================================
Files 654 654 Lines 187560 187814 +254 Branches 36087 36132 +45 ==========================================
+ Hits 165800 166048 +248 - Misses 14996 15007 +11 + Partials 6764 6759 -5 
Files with missing linesCoverage Δ
lib/internal/modules/package_json_reader.js99.39% <100.00%> (+<0.01%)⬆️

... and 49 files with indirect coverage changes

@JakobJingleheimer

Copy link
Copy Markdown
MemberAuthor

Can you add a test?

Yes, I intend to do, but I have to re-figure out how to re-produce it. I'm 100% certain this fixes the issue and does not cause adverse results, so can we land this without the test-case and add it subsequently so users can get the fix rather than wait?

@JakobJingleheimer

JakobJingleheimer commented Nov 12, 2024

Copy link
Copy Markdown
MemberAuthor

@aduh95 now that I re-read the updated title, I think it's actually not accurate: the issue does not occur when findPackageJSON(nonexistent), but rather when ESMLoader can't resolve the target, which is subtly different.

@aduh95

Copy link
Copy Markdown
Contributor

so can we land this without the test-case and add it subsequently

Let’s not, without a test we cannot detect regressions.

@JakobJingleheimer

Copy link
Copy Markdown
MemberAuthor

@AugustinMauroy found the reproduction 🎉 https://github.com/AugustinMauroy/issue-node-findpackagejson

@ljharb

ljharb commented Dec 28, 2024

Copy link
Copy Markdown
Member

fix LGTM but i agree this should probably have a test case before landing

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

moduleIssues and PRs related to the module subsystem.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@JakobJingleheimer@nodejs-github-bot@aduh95@ljharb@jasnell@GeoffreyBooth@anonrig