fix: guard _resolveGitState against undefined gitRepository (fixes #316425)#316430
Closed
vs-code-engineering[bot] wants to merge 2 commits into
Closed
fix: guard _resolveGitState against undefined gitRepository (fixes #316425)#316430vs-code-engineering[bot] wants to merge 2 commits into
vs-code-engineering[bot] wants to merge 2 commits into
Conversation
…16425) When sessionWorkspace.folders[0].gitRepository is undefined, the produce an object without gitHubInfo, which then triggered a TypeError in the derived observable in githubService.ts. Guard early by returning if gitRepository is absent, and remove the non-null assertion since the guard makes it unnecessary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The guard at line 846 narrows folder.gitRepository to non-undefined, but TypeScript does not carry that narrowing into the autorun closure. Extract gitRepository into a const after the guard so the spread in the closure sees the definite type. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Closing as superseded. The same null-safety fix for |
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.
🔧 Error Fix
Summary
Error:
TypeError: Cannot read properties of undefined (reading 'read')ingithubService.ts:108inside a derived observable computation.The crash occurs when
LocalNewSession._resolveGitState()spreadsthis.sessionWorkspace.folders[0].gitRepository!whilegitRepositoryisundefined. The spread ofundefinedproduces an object missinggitHubInfo, so when the observable chain propagates to the derived ingithubService.ts:108,gitHubInfo.read(reader)throws becausegitHubInfoisundefined.This is a new regression in 1.121.0-insider, introduced when
gitRepositorywas made optional onISessionWorkspaceFolder(commit1e8d5efd— "sessions: refactor ISession workspace model").Fixes #316425
Recommended reviewer:
@sandy081Culprit Commit
1e8d5efdby@sandy081Code Flow
graph TD A["$onDidChangeRepository / updateState"] --> B["observable.set() propagation"] B --> C["LocalNewSession._resolveGitState autorun"] C --> D["...folders[0].gitRepository! — gitRepository is undefined"] D --> E["Spread produces object WITHOUT gitHubInfo"] E --> F["_workspaceData.set() triggers derived chain"] F --> G["githubService.ts:108 — gitHubInfo.read(reader) → TypeError"]Affected Files
copilotChatSessionsProvider.ts_resolveGitState()spreads undefinedgitRepositorygithubService.tsgitHubInfo.read(reader)on malformed objectHow the Fix Works
Added an early guard in
_resolveGitState()to return immediately whenfolder.gitRepositoryisundefined. This fixes the bug at the data producer, not the crash site. The!non-null assertion is removed since the guard ensuresgitRepositoryis always defined when the spread executes.Recommended Owner
@sandy081errors-fix-driver — cycle 6
Trigger: cron_merge_conflict · Head:
4a1a5cddde8ab354001e4aff2053c47e7476a34a(4a1a5cd)copilotChatSessionsProvider.tsPush: yes —
4a1a5cd· Copilot rerequested: not applicable (PR has zero diff)Ready gate: not marking ready — PR now has zero diff against main (
LocalNewSessionwas removed upstream, making this fix moot). Recommend closing this PR as the underlying issue no longer applies.