Avoid TypeError in ObservableGit when gitApi.repositories is transiently nullish#313571
Avoid TypeError in ObservableGit when gitApi.repositories is transiently nullish#313571bryanchen-d merged 3 commits intomainfrom
ObservableGit when gitApi.repositories is transiently nullish#313571Conversation
…vable yields nullish Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/bbec7783-1ebc-4174-b1ab-02e8d2edf814 Co-authored-by: bryanchen-d <41454397+bryanchen-d@users.noreply.github.com>
mapObservableArrayCached when source observable yields nullish
|
@copilot why not fix it in extensions/copilot/src/platform/inlineEdits/common/observableGit.ts? what's the typing of items.read() returns? I think we should fix the typing if anywhere in the chain of flow that assign an nullish value while it is not supposed to be null by typing |
…hange Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/deaf79f3-70fb-43f7-a1dd-946a4d307a3d Co-authored-by: bryanchen-d <41454397+bryanchen-d@users.noreply.github.com>
Good point — moved the fix into The typing chain is all non-null: |
mapObservableArrayCached when source observable yields nullishObservableGit when gitApi.repositories is transiently nullish
There was a problem hiding this comment.
Pull request overview
This PR hardens Copilot Chat’s ObservableGit initialization against a real-world Git extension API contract violation where gitApi.repositories can be transiently undefined, preventing a TypeError: e is not iterable from propagating into mapObservableArrayCached/ArrayMap.setItems.
Changes:
- Coerce
gitApi.repositoriesto[]at the Git API consumption boundary inObservableGit.init.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/platform/inlineEdits/common/observableGit.ts | Guards against transiently nullish gitApi.repositories by defaulting to an empty array when creating the repos observable. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
Telemetry reports an unhandled
TypeError: e is not iterableoriginating fromArrayMap.setItemsinsidemapObservableArrayCached. The minified stack (BOe.setItems←Wd._computeFn←recomputeInitiallyAndOnChange←init) maps toObservableGit.initin the Copilot Chat extension. Although the typing chain is fully non-null (mapObservableArrayCachedtakesIObservable<readonly TIn[]>, andreposis built fromgitApi.repositoriestypedRepository[]), the git extension API can transiently returnundefinedfrom itsrepositoriesgetter (e.g. during extension reload), violating its own type contract and propagating a nullish value intoArrayMap.setItems'sfor...ofloop.Description
extensions/copilot/src/platform/inlineEdits/common/observableGit.ts— coerce a nullishgitApi.repositoriesto[]at the boundary where the git extension API is consumed. This is the actual point in the chain where reality diverges from the declared typing, so the guard belongs here rather than in the generic observable utility.The generic
mapObservableArrayCachedutility is left unchanged, preserving itsreadonly TIn[]contract so future violations elsewhere are not silently masked.