Skip to content

fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r#10705

Merged
zkochan merged 3 commits intopnpm:mainfrom
ishan8351:fix-why-r-crash
Feb 27, 2026
Merged

fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r#10705
zkochan merged 3 commits intopnpm:mainfrom
ishan8351:fix-why-r-crash

Conversation

@ishan8351
Copy link
Copy Markdown
Contributor

Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during invokation of pkgSnapshotToResolution.

This PR wraps resolution and integrity steps with if (pkgSnapshot). Also, added unit test for the same.

Fixes #10700

Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during
invokation of pkgSnapshotToResolution.

This commit wraps resolution and integrity steps with if (pkgSnapshot).
Also, added unit test for the same.

Fixes pnpm#10700
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a TypeError crash in pnpm why -r when pkgSnapshot is undefined during the resolution process. The issue occurred because the code attempted to access properties of an undefined pkgSnapshot object without proper null checking.

Changes:

  • Added a null check to wrap the resolution and integrity extraction code when pkgSnapshot might be undefined
  • Added a unit test to verify the fix handles missing package snapshots without crashing
  • Added a changeset documenting the fix

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
reviewing/dependencies-hierarchy/src/getPkgInfo.ts Added conditional check to prevent accessing undefined pkgSnapshot properties
reviewing/dependencies-hierarchy/test/getPkgInfo.test.ts Added test case for handling missing package snapshots
.changeset/famous-cloths-press.md Added changeset entry for the patch fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

optional = pkgSnapshot.optional
if ('integrity' in pkgSnapshot.resolution) {
integrity = pkgSnapshot.resolution.integrity as string
if (pkgSnapshot){
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

Missing space before opening brace. The codebase consistently uses if (pkgSnapshot) { with a space before the brace. This should be if (pkgSnapshot) { instead of if (pkgSnapshot){.

Suggested change
if (pkgSnapshot){
if (pkgSnapshot) {

Copilot uses AI. Check for mistakes.
zkochan and others added 2 commits February 27, 2026 15:12
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@zkochan zkochan changed the title fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r Feb 27, 2026
@zkochan zkochan merged commit d3a0765 into pnpm:main Feb 27, 2026
10 checks passed
@welcome
Copy link
Copy Markdown

welcome bot commented Feb 27, 2026

Congrats on merging your first pull request! 🎉🎉🎉

zkochan added a commit that referenced this pull request Mar 7, 2026
…why -r` (#10705)

* fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r

Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during
invokation of pkgSnapshotToResolution.

This commit wraps resolution and integrity steps with if (pkgSnapshot).
Also, added unit test for the same.

close #10700

* fix: handle undefined pkgSnapshot in pnpm why -r

* Apply suggestions from code review

#10700

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
zkochan added a commit that referenced this pull request Mar 7, 2026
…why -r` (#10705)

* fix(dependencies-hierarchy): handle undefined pkgSnapshot in pnpm why -r

Running pnpm why -r crashes with TypeError due to undefined pkgSnapshot during
invokation of pkgSnapshotToResolution.

This commit wraps resolution and integrity steps with if (pkgSnapshot).
Also, added unit test for the same.

close #10700

* fix: handle undefined pkgSnapshot in pnpm why -r

* Apply suggestions from code review

#10700

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

pnpm why -r crashes with TypeError: Cannot read properties of undefined (reading 'resolution') at pkgSnapshotToResolution

3 participants