fix: guard against null rightUri in SCM resolveChangeCommand (fixes #315292)#315341
Open
vs-code-engineering[bot] wants to merge 1 commit intomainfrom
Open
fix: guard against null rightUri in SCM resolveChangeCommand (fixes #315292)#315341vs-code-engineering[bot] wants to merge 1 commit intomainfrom
vs-code-engineering[bot] wants to merge 1 commit intomainfrom
Conversation
…315292) When rightUri is undefined for certain git status types (e.g. BOTH_DELETED, ADDED_BY_US), resolveChangeCommand passes undefined to the vscode.open command. After serialization through the extension host boundary, undefined becomes null, causing URI.from(null) to throw 'Cannot read properties of null (reading scheme)'. Fall back to resource.resourceUri (always defined) when rightUri is undefined. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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:
Cannot read properties of null (reading 'scheme')— aTypeErrorthrown when opening an SCM resource in the editor viaURI.from()with anullargument.Root cause: In the git extension's
ResourceCommandResolver.resolveChangeCommand(), whenleftUriis falsy and the merge-editor branch is not taken,resource.rightUriis passed directly as the first argument to thevscode.opencommand. For certain git status types (BOTH_DELETED,ADDED_BY_US,ADDED_BY_THEM, etc.),getRightResource()returns{}, makingrightUriundefined. After serialization through the extension host protocol boundary,undefinedbecomesnullin JSON, so the_workbench.opencommand handler receivesnullasresourceArgand callsURI.from(null), which crashes readingnull.scheme.Impact: 875 users affected on stable 1.119.0 across Windows, Mac, and Linux.
Fixes #315292
Recommended reviewer:
@lszomoruCulprit Commit
This is a latent bug — the code path has existed for a long time. No single culprit commit introduced it. The regression in 1.119.0 is likely due to a change in user behavior or new SCM status types triggering the unguarded path. Prior occurrences: #244373, #230645.
Code Flow
sequenceDiagram participant User participant SCMViewPane as scmViewPane.ts participant CommandService as commandService.ts participant EditorCommands as editorCommands.ts participant URI as uri.ts participant GitExt as git/repository.ts User->>SCMViewPane: Click SCM resource SCMViewPane->>SCMViewPane: open() at line 1726 Note over SCMViewPane: e.element.command.arguments[0] is null SCMViewPane->>CommandService: executeCommand('_workbench.open', null, ...) CommandService->>EditorCommands: handler(resourceArg=null) EditorCommands->>URI: URI.from(null, true) URI-->>URI: 💥 null.scheme → TypeError Note over GitExt: Producer: resolveChangeCommand()<br/>passes rightUri (undefined) as arg[0]<br/>serialized to null across ext host boundaryAffected Files
extensions/git/src/repository.tsresolveChangeCommand()passes potentially-undefinedrightUrias command argumentsrc/vs/workbench/browser/parts/editor/editorCommands.ts:463URI.from(resourceArg)where resourceArg is nullsrc/vs/base/common/uri.ts:343components.schemeon nullsrc/vs/workbench/contrib/scm/browser/scmViewPane.ts:1726Repro Steps
BOTH_DELETEDorADDED_BY_USgit.openDiffOnClickenabled (default), click on the resource in the SCM viewresolveChangeCommandproduces a command withrightUri= undefined_workbench.openhandler receives null → crashHow the Fix Works
Chosen approach (
extensions/git/src/repository.ts): Changed line 543 fromresource.rightUritoresource.rightUri ?? resource.resourceUri. This fixes the problem at the data producer —resolveChangeCommand()is where the invalid (undefined) value enters the command arguments array. TheresourceUrigetter always returns a validUri(it is typed as non-nullable), so it is a safe fallback. This follows the principle of fixing at the data producer rather than guarding at the crash site.Alternatives considered: Adding a null guard in
editorCommands.tsbeforeURI.from()— rejected because that would be a crash-site guard that silences the error without fixing the producer, and would mask any future callers passing invalid data through the command bus.Recommended Owner
@lszomoru— primary maintainer of the git extension (extensions/git/) and author of most recent changes torepository.ts.