{"record":{"id":"2b2575089c736cfc","repo":"github/copilot-sdk","slug":"failed-to-fetch-legacy-package-lock-json-w","errorCode":null,"errorMessage":"failed to fetch legacy package-lock.json: %w","messagePattern":"failed to fetch legacy package-lock\\.json: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":354,"sourceCode":"\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) {\n\turl := fmt.Sprintf(packageLockURLFmt, gitRef)\n\tfmt.Printf(\"Falling back to %s...\\n\", url)\n\n\tresp, err := http.Get(url)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch legacy package-lock.json: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch legacy package-lock.json: %s\", resp.Status)\n\t}\n\n\tvar packageLock struct {\n\t\tPackages map[string]struct {\n\t\t\tVersion string `json:\"version\"`\n\t\t} `json:\"packages\"`\n\t}\n\tif err := json.NewDecoder(resp.Body).Decode(&packageLock); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse legacy package-lock.json: %w\", err)\n\t}\n\tpkg, ok := packageLock.Packages[\"node_modules/@github/copilot\"]\n\tif !ok || pkg.Version == \"\" {\n\t\treturn \"\", fmt.Errorf(\"could not find copilotCliVersion in package.json or @github/copilot in package-lock.json\")\n\t}","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L336-L372","documentation":"This error wraps the underlying transport error from http.Get when fetching the legacy package-lock.json from the repo at a given git ref. The bundler falls back to the legacy lockfile to resolve the @github/copilot CLI version; if the HTTP request itself fails (DNS, TLS, connection refused, timeout), this error is thrown so the caller (fetchCLIVersionFromRepo) sees a descriptive chain.","triggerScenarios":"http.Get on the packageLockURLFmt URL built from the gitRef fails at the transport level — DNS resolution failure, connection refused, TLS handshake failure, or no network — inside fetchLegacyCLIVersionFromRepo, which is the fallback path of fetchCLIVersionFromRepo.","commonSituations":"Offline or corporate-proxy-restricted CI runners; a bad gitRef producing an invalid URL; GitHub being unreachable or rate-limiting at the TCP/TLS layer; typos in the repo host configured for the bundler.","solutions":["Check network connectivity from the machine running the bundler (curl the URL manually).","Verify the gitRef passed in resolves to a real ref so the constructed URL is valid.","Configure proxy environment variables (HTTPS_PROXY) if behind a corporate proxy.","Retry later if GitHub is temporarily unreachable; the error chain shows the root cause.","Bypass the fallback by ensuring the primary version source (package.json copilotCliVersion) succeeds."],"exampleFix":"// before\nresp, err := http.Get(url)\nif err != nil {\n\treturn \"\", fmt.Errorf(\"failed to fetch legacy package-lock.json: %w\", err)\n}\n// after\nclient := &http.Client{Timeout: 30 * time.Second}\nresp, err := client.Get(url)\nif err != nil {\n\treturn \"\", fmt.Errorf(\"failed to fetch legacy package-lock.json at %s: %w\", url, err)\n}","handlingStrategy":"retry","validationCode":"url := fmt.Sprintf(packageLockURLFmt, gitRef)\nif _, err := net.LookupHost(\"github.com\"); err != nil {\n\treturn errors.New(\"network unreachable: cannot fetch legacy package-lock.json\")\n}","typeGuard":null,"tryCatchPattern":"var v string\nvar err error\nfor i := 0; i < 3; i++ {\n\tv, err = fetchLegacyCLIVersionFromRepo(gitRef)\n\tif err == nil || !errors.Is(err, context.DeadlineExceeded) && !isNetErr(err) {\n\t\tbreak\n\t}\n\ttime.Sleep(time.Duration(1<<i) * time.Second)\n}","preventionTips":["Pre-resolve cliVersion from package.json so the legacy fallback rarely runs.","Set an http.Client timeout instead of the default no-timeout http.Get.","Configure HTTPS_PROXY in restricted network environments.","Run a connectivity preflight (curl HEAD) in CI before the bundler."],"tags":["network","http","fallback","github"],"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"}