fix: handle network errors in computePreferredOrganizationName (fixes #319001)#319009
Open
vs-code-engineering[bot] wants to merge 1 commit into
Open
fix: handle network errors in computePreferredOrganizationName (fixes #319001)#319009vs-code-engineering[bot] wants to merge 1 commit into
vs-code-engineering[bot] wants to merge 1 commit into
Conversation
…319001) The computePreferredOrganizationName method calls getCurrentAuthedUser() which makes a network request to the GitHub API. When the network is unavailable, this throws a TypeError: fetch failed that propagates as an unhandled error. The function already handles errors for getUserOrganizations but not for this initial auth check. Add try/catch around getCurrentAuthedUser() to gracefully handle network failures by returning undefined (same behavior as when the user is not signed in). This is a best-effort operation - if the network is unavailable, org-specific chat resources simply won't load. 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.
Summary
The
computePreferredOrganizationNamemethod in the Copilot Chat extension'sGitHubOrgChatResourcesServicecallsgetCurrentAuthedUser()which performs a network fetch to the GitHub API. When the network is unavailable (offline, DNS failure, connection refused), Node.js throws aTypeError: fetch failedthat propagates as an unhandled error to telemetry. This affects all platforms (linux, win32, darwin) and impacts ~553 users with 1324 hits on version 0.50.0 alone.Fixes #319001
Recommended reviewer:
@pwang347Culprit Commit
Not identified — pre-existing. The bucket history shows hits across all tracked extension versions (0.50.0, multiple daily builds from 0.50.2026052501 through 0.50.2026052702), indicating this is a long-standing gap in error handling rather than a recent regression. The file was created in January 2026 and the network error path was never guarded.
Code Flow
sequenceDiagram participant Caller as getPreferredOrganizationName participant Compute as computePreferredOrganizationName participant OctoKit as OctoKitService participant Fetcher as FetcherService participant Network as Node fetch Caller->>Compute: await computePreferredOrganizationName() Compute->>OctoKit: getCurrentAuthedUser() OctoKit->>Fetcher: fetch(github api /user) Fetcher->>Network: native fetch() Note over Network: Network unavailable Network-->>Fetcher: TypeError: fetch failed Fetcher-->>OctoKit: throws OctoKit-->>Compute: throws Note over Compute: No try/catch here Compute-->>Caller: unhandled error to telemetryAffected Files
extensions/copilot/src/extension/agents/vscode-node/githubOrgChatResourcesService.tsconst currentUser = await this.octoKitService.getCurrentAuthedUser()— no try/catch unlike L155extensions/copilot/src/platform/github/common/octoKitServiceImpl.tsgetCurrentAuthedUserdelegates to network fetchextensions/copilot/src/platform/github/common/githubAPI.tsfetcherService.fetch()— network-level errors not caughtRepro Steps
getPreferredOrganizationName()(e.g., opening the Copilot chat panel)TypeError: fetch failedappears in error telemetryHow the Fix Works
Chosen approach (
githubOrgChatResourcesService.ts): Wrap thegetCurrentAuthedUser()call in a try/catch that logs the error and returnsundefined. This is the same pattern already used at line 155-165 forgetUserOrganizations()in the same function. The operation is best-effort — when the network is unavailable, the user simply won't see org-specific chat resources (identical behavior to when not signed in). This fixes the error at the producer of the unhandled rejection (the missing error boundary), not at a crash site or downstream consumer.Alternatives considered: Adding error handling inside
makeGitHubAPIRequestorgetCurrentAuthedUserwas rejected because those are shared utilities used by many callers that may want network errors to propagate. The correct place is the consumer that knows the operation is optional.Recommended Owner
@pwang347— primary author ofgithubOrgChatResourcesService.ts(created the file and all subsequent modifications). Active in the repo (commits as recently as May 29, 2026). Liveness check: active.errors-fix-driver — cycle 1
Trigger: cron_check_failed · Head: pushed (merge main + type fix)
Compile & Hygiene(real)Push: yes · Copilot rerequested: ok
Ready gate: ci pending → not marking ready this cycle