{"record":{"id":"21805d7414b594d0","repo":"github/copilot-sdk","slug":"failed-to-fetch-w","errorCode":null,"errorMessage":"failed to fetch: %w","messagePattern":"failed to fetch: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":325,"sourceCode":"\t// v0.0.0-20240101120000-abcdef123456 -> abcdef123456 (pseudo-version)\n\tgitRef := sdkVersion\n\n\t// Pseudo-versions end with a 12-character commit hash.\n\t// Format: vX.Y.Z-yyyymmddhhmmss-abcdefabcdef\n\tif idx := strings.LastIndex(sdkVersion, \"-\"); idx != -1 {\n\t\tsuffix := sdkVersion[idx+1:]\n\t\t// Use the commit hash when present so we fetch the exact source snapshot.\n\t\tif len(suffix) == 12 && isHex(suffix) {\n\t\t\tgitRef = suffix\n\t\t}\n\t}\n\n\turl := fmt.Sprintf(packageJSONURLFmt, gitRef)\n\tfmt.Printf(\"Fetching %s...\\n\", url)\n\n\tresp, err := http.Get(url)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch package.json: %s\", resp.Status)\n\t}\n\n\tvar packageJSON struct {\n\t\tCopilotCLIVersion string `json:\"copilotCliVersion\"`\n\t}\n\n\tif err := json.NewDecoder(resp.Body).Decode(&packageJSON); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse package.json: %w\", err)\n\t}\n\n\tif packageJSON.CopilotCLIVersion == \"\" {\n\t\treturn fetchLegacyCLIVersionFromRepo(gitRef)\n\t}","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L307-L343","documentation":"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.","triggerScenarios":"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.","commonSituations":"Working offline; corporate proxy/firewall blocking raw.githubusercontent.com; DNS failure; IPv6 issues in containers/CI.","solutions":["Check internet connectivity and retry (curl the printed URL)","Configure HTTPS_PROXY if behind a corporate proxy","Retry later if GitHub is having an outage","Pin the SDK to a version whose package.json URL is known-reachable"],"exampleFix":"// before: failed to fetch: dial tcp: lookup raw.githubusercontent.com: no such host\n// after:\n// $ export HTTPS_PROXY=http://proxy.corp:8080\n// $ bundler ./cmd/app","handlingStrategy":"retry","validationCode":"url := fmt.Sprintf(packageJSONURLFmt, gitRef)\nif _, err := http.NewRequest(http.MethodGet, url, nil); err != nil {\n    return fmt.Errorf(\"bad package.json URL: %v\", err)\n}\n// optionally: net.DialTimeout probe before the real request","typeGuard":null,"tryCatchPattern":"cli, err := detectCLIVersion()\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) || strings.Contains(err.Error(), \"failed to fetch\") {\n        time.Sleep(backoff)\n        // retry with exponential backoff, or use a cached CLI version\n    }\n}","preventionTips":["Cache the last successfully fetched CLI version for offline fallback","Configure HTTPS_PROXY in restricted networks","Add timeouts via a custom http.Client instead of http.Get's default"],"tags":["network","http","github"],"backgroundTag":"network-request-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}