Skip to content

fix: handle network errors in computePreferredOrganizationName (fixes #319001)#319009

Open
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/copilot-fetch-failed-319001-b514c695fbe1d9dc
Open

fix: handle network errors in computePreferredOrganizationName (fixes #319001)#319009
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/copilot-fetch-failed-319001-b514c695fbe1d9dc

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

@vs-code-engineering vs-code-engineering Bot commented May 29, 2026

Summary

The computePreferredOrganizationName method in the Copilot Chat extension's GitHubOrgChatResourcesService calls getCurrentAuthedUser() which performs a network fetch to the GitHub API. When the network is unavailable (offline, DNS failure, connection refused), Node.js throws a TypeError: fetch failed that 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: @pwang347

Culprit 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 telemetry
Loading

Affected Files

File Role Evidence
extensions/copilot/src/extension/agents/vscode-node/githubOrgChatResourcesService.ts root cause (missing error handling) L128: const currentUser = await this.octoKitService.getCurrentAuthedUser() — no try/catch unlike L155
extensions/copilot/src/platform/github/common/octoKitServiceImpl.ts call chain L35-41: getCurrentAuthedUser delegates to network fetch
extensions/copilot/src/platform/github/common/githubAPI.ts call chain (fetch) L221-226: fetcherService.fetch() — network-level errors not caught

Repro Steps

  1. Open VS Code with the Copilot Chat extension active
  2. Disconnect from the network (disable WiFi/Ethernet)
  3. Trigger any action that calls getPreferredOrganizationName() (e.g., opening the Copilot chat panel)
  4. The TypeError: fetch failed appears in error telemetry

How the Fix Works

Chosen approach (githubOrgChatResourcesService.ts): Wrap the getCurrentAuthedUser() call in a try/catch that logs the error and returns undefined. This is the same pattern already used at line 155-165 for getUserOrganizations() 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 makeGitHubAPIRequest or getCurrentAuthedUser was 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 of githubOrgChatResourcesService.ts (created the file and all subsequent modifications). Active in the repo (commits as recently as May 29, 2026). Liveness check: active.

Generated by errors-fix · ● 58.1M ·


errors-fix-driver — cycle 1

Trigger: cron_check_failed · Head: pushed (merge main + type fix)

Item Action
CI: Compile & Hygiene (real) Fixed type annotation, merged main

Push: yes · Copilot rerequested: ok

Ready gate: ci pending → not marking ready this cycle

Generated by errors-fix-driver · ● 85.9M ·

…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>
Copilot AI review requested due to automatic review settings May 29, 2026 16:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot requested review from Copilot and pwang347 May 29, 2026 16:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot marked this pull request as ready for review May 29, 2026 16:23
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 29, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Error] [GitHub.copilot-chat] unhandlederror-fetch failed

2 participants