{"record":{"id":"ecb2a49d610f7408","repo":"github/copilot-sdk","slug":"failed-to-fetch-cli-version-w","errorCode":null,"errorMessage":"failed to fetch CLI version: %w","messagePattern":"failed to fetch CLI version: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":277,"sourceCode":"}\n\n// detectCLIVersion detects the CLI version by:\n// 1. Running \"go list -m\" to get the copilot-sdk version from the user's go.mod\n// 2. Fetching package.json from the SDK repo at that version\n// 3. Extracting the pinned Copilot CLI version from it\nfunc detectCLIVersion() (string, error) {\n\t// Get the SDK version from the user's go.mod\n\tsdkVersion, err := getSDKVersion()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get SDK version: %w\", err)\n\t}\n\n\tfmt.Printf(\"Found copilot-sdk %s in go.mod\\n\", sdkVersion)\n\n\t// Fetch package.json from the SDK repo at that version\n\tcliVersion, err := fetchCLIVersionFromRepo(sdkVersion)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch CLI version: %w\", err)\n\t}\n\n\treturn cliVersion, nil\n}\n\n// getSDKVersion runs \"go list -m\" to get the copilot-sdk version from go.mod\nfunc getSDKVersion() (string, error) {\n\tcmd := exec.Command(\"go\", \"list\", \"-m\", \"-f\", \"{{.Version}}\", sdkModule)\n\toutput, err := cmd.Output()\n\tif err != nil {\n\t\tif exitErr, ok := err.(*exec.ExitError); ok {\n\t\t\treturn \"\", fmt.Errorf(\"go list failed: %s\", string(exitErr.Stderr))\n\t\t}\n\t\treturn \"\", err\n\t}\n\n\tversion := strings.TrimSpace(string(output))\n\tif version == \"\" {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L259-L295","documentation":"After resolving the SDK version, detectCLIVersion fetches package.json from the SDK repo at that version to read the pinned copilotCliVersion. Failure of that network fetch is wrapped as 'failed to fetch CLI version'. The CLI version pin lives in the repo's package.json, not in go.mod.","triggerScenarios":"fetchCLIVersionFromRepo returns an error because the GitHub HTTP request fails, returns a non-200 status, or package.json cannot be parsed; this is re-wrapped by detectCLIVersion.","commonSituations":"Offline or behind a corporate proxy blocking raw.githubusercontent.com; the resolved SDK version has no matching git tag (misaligned release); GitHub rate limiting or outage.","solutions":["Check network connectivity / proxy settings (HTTPS_PROXY) and retry","Verify the SDK version from go.mod has a corresponding release/tag in the SDK repo","Run `go get` to move to a released copilot-sdk version whose tag exists","If rate-limited, wait or set a GITHUB_TOKEN if supported, then retry"],"exampleFix":"// before: failed to fetch CLI version: failed to fetch package.json: 404 Not Found\n// after: pin a released SDK version\n// before go.mod: copilot-sdk v0.0.0-dev\n// after go.mod: copilot-sdk v0.5.0","handlingStrategy":"retry","validationCode":"ver, err := exec.Command(\"go\", \"list\", \"-m\", \"-f\", \"{{.Version}}\", sdkModule).Output()\nif err == nil {\n    ref := strings.TrimSpace(string(ver))\n    resp, err := http.Head(fmt.Sprintf(packageJSONURLFmt, ref))\n    if err != nil || resp.StatusCode != 200 {\n        log.Printf(\"package.json unreachable for %s; use a released SDK version\", ref)\n    }\n}","typeGuard":null,"tryCatchPattern":"cli, err := detectCLIVersion()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to fetch CLI version\") {\n        // fall back to a locally installed copilot CLI or retry with backoff\n    }\n}","preventionTips":["Pin copilot-sdk to released (tagged) versions only","Ensure CI has network access to raw.githubusercontent.com","Set proxy env vars when behind a firewall"],"tags":["network","http","versioning","cli"],"backgroundTag":"http-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"}