{"record":{"id":"bf4a02f301b17b4d","repo":"github/copilot-sdk","slug":"failed-to-fetch-package-json-s","errorCode":null,"errorMessage":"failed to fetch package.json: %s","messagePattern":"failed to fetch package\\.json: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":330,"sourceCode":"\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}\n\n\treturn packageJSON.CopilotCLIVersion, nil\n}\n\nfunc fetchLegacyCLIVersionFromRepo(gitRef string) (string, error) {","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L312-L348","documentation":"If the package.json fetch succeeds at the transport level but the server responds with a status other than 200, fetchCLIVersionFromRepo fails with the response status embedded in the message. Non-200 typically means the requested git ref (SDK version) does not exist in the repo or the file moved.","triggerScenarios":"http.Get returns 404 (git tag/ref not found), 403 (rate limit), 5xx (GitHub error) for the packageJSONURLFmt URL; the status code check rejects it.","commonSituations":"go.mod contains a pseudo-version or dev version with no matching git tag; GitHub API rate limiting (403) without credentials; renamed repo paths in newer SDK versions.","solutions":["Check the status in the message: 404 → the SDK version has no matching tag; switch to a released version via `go get copilot-sdk@latest`","For 403 rate limit, wait or use authenticated access, then retry","For 5xx, retry after confirming GitHub status","Verify the URL printed before the failure resolves in a browser"],"exampleFix":"// before go.mod: copilot-sdk v0.0.0-20240101000000-abcdef123456 (no tag) -> 404\n// after go.mod: copilot-sdk v0.5.0 -> package.json found","handlingStrategy":"fallback","validationCode":"resp, err := http.Get(url)\nif err != nil {\n    return err\n}\nif resp.StatusCode == 403 && resp.Header.Get(\"X-RateLimit-Remaining\") == \"0\" {\n    return errors.New(\"GitHub rate limited; wait or authenticate\")\n}\nif resp.StatusCode != 200 {\n    return fmt.Errorf(\"package.json unavailable: %s\", resp.Status)\n}","typeGuard":null,"tryCatchPattern":"cli, err := detectCLIVersion()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to fetch package.json: 404\") {\n        // fall back to a default CLI version or prompt user to upgrade SDK\n    }\n}","preventionTips":["Only use copilot-sdk versions that have a published git tag","Respect GitHub rate limits; add authentication if the tool supports it","Pre-check the tag exists: `git ls-remote --tags <repo> <version>`"],"tags":["http","github","versioning"],"backgroundTag":"http-non-200-response","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"}