Skip to content

Avoid nil package.json crash when resolving peer dependencies#4479

Merged
jakebailey merged 4 commits into
mainfrom
copilot/fix-crash-nil-contents
Jun 30, 2026
Merged

Avoid nil package.json crash when resolving peer dependencies#4479
jakebailey merged 4 commits into
mainfrom
copilot/fix-crash-nil-contents

Conversation

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Module resolution could panic when peerDependencies package ID calculation received a cached package.json entry with nil contents.

  • Resolver

    • Check InfoCacheEntry.Exists() before reading a peer package’s Contents.
    • Treat nil-content peer package entries the same as missing peer package metadata.
  • Regression coverage

    • Added a deterministic resolver race test that reproduces a nil-content peer package.json cache entry during peer dependency resolution.
peerPackageJson := r.getPackageJsonInfo(nodeModules + name)
if peerPackageJson.Exists() {
    version := peerPackageJson.Contents.Version.Value
    // include peer version in package ID
}

Copilot AI and others added 3 commits June 29, 2026 23:49
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crash from nil contents of package.json Avoid nil package.json crash when resolving peer dependencies Jun 29, 2026
Copilot AI requested a review from DanielRosenwasser June 29, 2026 23:57
@DanielRosenwasser DanielRosenwasser marked this pull request as ready for review June 30, 2026 00:33
Copilot AI review requested due to automatic review settings June 30, 2026 00:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a potential panic in the module resolver when computing a package ID with peerDependencies, where the peer’s cached package.json cache entry can be present but have nil Contents. The change ensures the resolver only reads peer package.json fields when the cache entry actually has parsed contents, and adds a deterministic concurrent regression test that reproduces the stale nil-contents cache entry scenario.

Changes:

  • Guard peer dependency package ID calculation with InfoCacheEntry.Exists() to avoid dereferencing nil Contents.
  • Add a deterministic race regression test that forces the nil-contents cache entry case during peer dependency resolution.
Show a summary per file
File Description
internal/module/resolver.go Uses InfoCacheEntry.Exists() before reading peer package.json contents while computing peer-dependent package IDs.
internal/module/resolver_test.go Adds a deterministic concurrent regression test for the nil-contents peer package.json cache entry scenario.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@jakebailey jakebailey added this pull request to the merge queue Jun 30, 2026
Merged via the queue into main with commit 1230cf2 Jun 30, 2026
22 checks passed
@jakebailey jakebailey deleted the copilot/fix-crash-nil-contents branch June 30, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash from nil Contents of package.json resolved through peerDependencies

5 participants