Skip to content

Fix Extension Host crash when there is no current project - #956

Open
1fanwang wants to merge 1 commit into
alefragnani:masterfrom
1fanwang:fix/938-guard-current-project
Open

Fix Extension Host crash when there is no current project#956
1fanwang wants to merge 1 commit into
alefragnani:masterfrom
1fanwang:fix/938-guard-current-project

Conversation

@1fanwang

@1fanwang 1fanwang commented Jul 28, 2026

Copy link
Copy Markdown

Description

The side bar decoration provider dereferences Container.currentProject without checking it, so it throws Cannot read properties of undefined (reading 'rootPath') whenever no current project is set. It runs once per tree item, so the errors flood the Extension Host until it terminates and Extension Bisect kicks in.

Fixes #938

Container._currentProject is declared but never initialized, and is only assigned from showStatusBar, which returns no value in four cases. Only the last needs an unmanaged folder:

  • projectManager.showProjectNameInStatusBar is false, so it never resolves even when the folder is a saved project
  • no folder open (empty window)
  • called with an explicit projectName
  • no project matches the open folder

strictNullChecks is not enabled, so typing the getter Project | undefined would not be enforced at the call site. The runtime guard is what fixes it.


Prerequisites Checklist

  • The code is up-to-date with the master branch
  • I have reviewed the CONTRIBUTING.md guidelines
  • The code follows the repository's coding style (TypeScript conventions, formatting, naming)
  • All changes are testable and have been manually tested

Regular PR

  • This PR must address an existing issue

Changes Made

  • Guard Container.currentProject before comparing its root path, as suggested in the issue.
  • Add SideBar Decoration Tests covering the unset current project plus existing behavior (current project decorated, others not, foreign schemes ignored). They intercept window.registerFileDecorationProvider to exercise the provider the extension actually registers, not a copy that could drift.

Testing

  • Tested locally with the extension running in VS Code
  • Tested on Windows (if applicable)
  • Tested on macOS (if applicable)
  • Tested on Linux (if applicable)
  • Tested on Remotes (Containers, WSL, etc.)
  • Verified existing functionality still works (no regressions)

npm test launches a real VS Code 1.130.0 via @vscode/test-electron. Not run on Windows, Linux or Remotes; the change is platform independent and does not touch the remote path.

The two new tests fail on master and pass with the fix. The pre-fix failure comes from the product file out/src/sidebar/decoration.js:15, matching the stack in the issue.

Raw logs: before the fix (2 failing)
$ git stash && npm test
  SideBar Decoration Tests
    ✔ should not decorate uris from other schemes
    ✔ should decorate the current project
    ✔ should not decorate a project which is not the current one
    1) should not throw when there is no current project
    2) should not decorate when there is no current project

  66 passing (2s)
  2 failing

  1) SideBar Decoration Tests
       should not throw when there is no current project:
     AssertionError [ERR_ASSERTION]: Got unwanted exception.
     Actual message: "Cannot read properties of undefined (reading 'rootPath')"
      at Context.<anonymous> (out/src/test/suite/decoration.test.js:59:16)

  2) SideBar Decoration Tests
       should not decorate when there is no current project:
     TypeError: Cannot read properties of undefined (reading 'rootPath')
      at Object.provideFileDecoration (out/src/sidebar/decoration.js:15:67)
      at Context.<anonymous> (out/src/test/suite/decoration.test.js:63:37)

Error: 2 tests failed.
Exit code:   1
Raw logs: after the fix (68 passing)
$ npm test
  SideBar Decoration Tests
    ✔ should not decorate uris from other schemes
    ✔ should decorate the current project
    ✔ should not decorate a project which is not the current one
    ✔ should not throw when there is no current project
    ✔ should not decorate when there is no current project

  68 passing (2s)
[main 2026-07-28T22:53:16.123Z] Extension host with pid 39824 exited with code: 0, signal: unknown.
Exit code:   0
Raw logs: Extension Host renderer log, same file across both runs
$ grep -c "reading 'rootPath'" .vscode-test/user-data/logs/<run>/window1/renderer.log
before the fix   20260728T155222 -> 2
after the fix    20260728T155309 -> 0

npm run lint reports 0 errors; the changed files add no new warnings.

Documentation

  • Updated README.md if adding user-facing features (if applicable)

Not applicable. This is a crash fix with no user-facing surface change.

Additional Notes

The guard is deliberately minimal, matching the suggestion in the issue. The other option, an undefined-typed getter checked at the call site, only holds once strictNullChecks is enabled.

`Container.currentProject` stays undefined until `showStatusBar` resolves a
project for the open folder, so the side bar decoration provider dereferenced
undefined and threw `Cannot read properties of undefined (reading 'rootPath')`
on every decoration request for the `projectManager-view` scheme. Because the
provider runs once per tree item, the errors flooded the Extension Host until
it terminated.

Guard the current project before comparing its root path, and cover the
provider with tests for both the set and unset cases.

Fixes alefragnani#938

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Copilot AI review requested due to automatic review settings July 28, 2026 23:01

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 an Extension Host crash in the Project Manager sidebar decoration provider by safely handling cases where no current project is set, and adds a focused test suite to prevent regressions.

Changes:

  • Add a runtime guard in the sidebar decoration provider to avoid dereferencing Container.currentProject when it’s unset.
  • Add a new Mocha test suite that captures the actual registered FileDecorationProvider and verifies behavior for: current project decorated, non-current not decorated, other schemes ignored, and “no current project” does not throw / does not decorate.

Reviewed changes

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

File Description
src/sidebar/decoration.ts Prevents crashes by guarding access to Container.currentProject before reading rootPath.
src/test/suite/decoration.test.ts Adds regression coverage for the sidebar decoration provider, including the “no current project” scenario that caused Extension Host crashes.

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.

[BUG] - Extension Host crash: "Cannot read properties of undefined (reading 'rootPath')" in side bar decoration provider when no current project is set

2 participants