{"record":{"id":"7e4f2b250dd21fbc","repo":"chenhg5/cc-connect","slug":"request-failed-w","errorCode":null,"errorMessage":"request failed: %w","messagePattern":"request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/update.go","lineNumber":224,"sourceCode":"}\n\n// fetchRelease returns the latest release. If pre=true, includes pre-releases.\nfunc fetchRelease(pre bool) (*githubRelease, error) {\n\tif pre {\n\t\treturn fetchLatestPreRelease()\n\t}\n\treturn fetchLatestStableRelease()\n}\n\n// fetchLatestPreRelease fetches the newest release (including pre-releases) from GitHub.\nfunc fetchLatestPreRelease() (*githubRelease, error) {\n\tclient := &http.Client{Timeout: 15 * time.Second}\n\treq, _ := http.NewRequest(\"GET\", githubAllAPI+\"?per_page=10\", nil)\n\treq.Header.Set(\"Accept\", \"application/vnd.github.v3+json\")\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"GitHub API returned HTTP %d\", resp.StatusCode)\n\t}\n\n\tvar releases []githubRelease\n\tif err := json.NewDecoder(resp.Body).Decode(&releases); err != nil {\n\t\treturn nil, fmt.Errorf(\"parse releases: %w\", err)\n\t}\n\n\tif len(releases) == 0 {\n\t\treturn nil, fmt.Errorf(\"no releases found\")\n\t}\n\n\t// Return the first (newest) release, which may be a pre-release\n\treturn &releases[0], nil","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/update.go#L206-L242","documentation":"fetchLatestPreRelease wraps any error from the HTTP client's Do() call with \"request failed: %w\". It means the GET request to the GitHub releases API failed at the transport level: DNS resolution, TCP connect, TLS, or the 15s timeout. It is not an HTTP status error — non-200 responses produce a different error.","triggerScenarios":"client.Do(req) in fetchLatestPreRelease returns a non-nil error: unreachable network, DNS failure for api.github.com, TLS problems, proxy misconfiguration, or the 15-second client timeout firing on a slow connection.","commonSituations":"Developer running `cc-connect update` (which calls fetchRelease) offline or behind a corporate proxy that blocks api.github.com; DNS misconfiguration in containers/VMs; slow networks hitting the 15s http.Client timeout; IPv6 issues; firewall dropping outbound 443.","solutions":["Check basic connectivity: curl -v https://api.github.com/repos/<owner>/<repo>/releases?per_page=10","If behind a proxy, set HTTPS_PROXY correctly for the process running cc-connect","Retry the update — transient network blips and GitHub brownouts are common","If timeouts persist, check firewall/DNS rules for api.github.com (or corporate blocking)","Run `cc-connect doctor` or equivalent network diagnostics if available"],"exampleFix":"// before\nclient := &http.Client{Timeout: 15 * time.Second}\n// after\nclient := &http.Client{Timeout: 60 * time.Second} // tolerate slow networks\nfor attempt := 0; attempt < 3; attempt++ {\n    resp, err := client.Do(req)\n    if err == nil { break }\n    time.Sleep(time.Duration(attempt+1) * time.Second)\n}","handlingStrategy":"retry","validationCode":"// before calling update, verify reachability:\nconn, err := net.DialTimeout(\"tcp\", \"api.github.com:443\", 5*time.Second)\nif err != nil { return fmt.Errorf(\"GitHub unreachable: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"// Go: inspect the wrapped error and retry with backoff\nif _, err := fetchRelease(); err != nil {\n    if strings.Contains(err.Error(), \"request failed\") {\n        var dnsErr *net.DNSError\n        if errors.As(err, &dnsErr) {\n            // DNS failure — check resolver/proxy\n        }\n        // otherwise transient: retry with backoff\n    }\n}","preventionTips":["Run update commands only with confirmed network access","Set HTTPS_PROXY when operating behind corporate proxies","Increase the http.Client timeout on slow links","Add retry with exponential backoff around GitHub API calls"],"tags":["network","http","github-api","update-checker","timeout"],"backgroundTag":"http-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}