github/copilot-sdk · error

failed to fetch

Error message

failed to fetch: %w

What it means

fetchCLIVersionFromRepo issues an http.Get against the package.json URL for the resolved git ref. Any transport-level failure (DNS, TLS, connection refused, timeout, proxy error) is wrapped as 'failed to fetch'. This happens before any status code check.

Solutions

  1. Check internet connectivity and retry (curl the printed URL)
  2. Configure HTTPS_PROXY if behind a corporate proxy
  3. Retry later if GitHub is having an outage
  4. Pin the SDK to a version whose package.json URL is known-reachable

Example fix

// before: failed to fetch: dial tcp: lookup raw.githubusercontent.com: no such host
// after:
// $ export HTTPS_PROXY=http://proxy.corp:8080
// $ bundler ./cmd/app
Defensive patterns

Strategy: retry

Validate before calling

url := fmt.Sprintf(packageJSONURLFmt, gitRef)
if _, err := http.NewRequest(http.MethodGet, url, nil); err != nil {
    return fmt.Errorf("bad package.json URL: %v", err)
}
// optionally: net.DialTimeout probe before the real request

Try / catch

cli, err := detectCLIVersion()
if err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) || strings.Contains(err.Error(), "failed to fetch") {
        time.Sleep(backoff)
        // retry with exponential backoff, or use a cached CLI version
    }
}

Prevention

When it happens

Trigger: http.Get returns a non-nil err for the package.json URL built from the SDK version's git ref — e.g. no network, blocked host, or invalid URL construction.

Common situations: Working offline; corporate proxy/firewall blocking raw.githubusercontent.com; DNS failure; IPv6 issues in containers/CI.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/21805d7414b594d0. Report an issue: GitHub.

Appendix: source

Thrown at go/cmd/bundler/main.go:325

	// v0.0.0-20240101120000-abcdef123456 -> abcdef123456 (pseudo-version)
	gitRef := sdkVersion

	// Pseudo-versions end with a 12-character commit hash.
	// Format: vX.Y.Z-yyyymmddhhmmss-abcdefabcdef
	if idx := strings.LastIndex(sdkVersion, "-"); idx != -1 {
		suffix := sdkVersion[idx+1:]
		// Use the commit hash when present so we fetch the exact source snapshot.
		if len(suffix) == 12 && isHex(suffix) {
			gitRef = suffix
		}
	}

	url := fmt.Sprintf(packageJSONURLFmt, gitRef)
	fmt.Printf("Fetching %s...\n", url)

	resp, err := http.Get(url)
	if err != nil {
		return "", fmt.Errorf("failed to fetch: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return "", fmt.Errorf("failed to fetch package.json: %s", resp.Status)
	}

	var packageJSON struct {
		CopilotCLIVersion string `json:"copilotCliVersion"`
	}

	if err := json.NewDecoder(resp.Body).Decode(&packageJSON); err != nil {
		return "", fmt.Errorf("failed to parse package.json: %w", err)
	}

	if packageJSON.CopilotCLIVersion == "" {
		return fetchLegacyCLIVersionFromRepo(gitRef)
	}

View on GitHub (pinned to cd8cf15dc3)