Avoid nil package.json crash when resolving peer dependencies#4479
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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 nilContents. - 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
andrewbranch
approved these changes
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Module resolution could panic when
peerDependenciespackage ID calculation received a cachedpackage.jsonentry with nil contents.Resolver
InfoCacheEntry.Exists()before reading a peer package’sContents.Regression coverage
package.jsoncache entry during peer dependency resolution.