{"record":{"id":"f955880f7669cd72","repo":"chenhg5/cc-connect","slug":"http-get-s-w","errorCode":null,"errorMessage":"HTTP GET %s: %w","messagePattern":"HTTP GET (.+?): %w","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/provider_presets.go","lineNumber":140,"sourceCode":"\tif err != nil {\n\t\tif c.data != nil {\n\t\t\tslog.Warn(\"all presets sources failed, using stale cache\", \"error\", err)\n\t\t\treturn c.data, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"fetch presets: %w\", err)\n\t}\n\n\tc.data = result\n\tc.fetchedAt = time.Now()\n\treturn c.data, nil\n}\n\nfunc fetchPresetsFromURL(url string, timeout time.Duration) (*ProviderPresetsResponse, error) {\n\tslog.Debug(\"fetching provider presets\", \"url\", url)\n\tclient := &http.Client{Timeout: timeout}\n\tresp, err := client.Get(url)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"HTTP GET %s: %w\", url, err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"HTTP GET %s: status %d\", url, resp.StatusCode)\n\t}\n\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read body from %s: %w\", url, err)\n\t}\n\n\tvar result ProviderPresetsResponse\n\tif err := json.Unmarshal(body, &result); err != nil {\n\t\treturn nil, fmt.Errorf(\"parse JSON from %s: %w\", url, err)\n\t}\n\treturn &result, nil\n}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/provider_presets.go#L122-L158","documentation":"`fetchPresetsFromURL` wraps any transport-level failure of `http.Client.Get` — DNS failure, connection refused, TLS error, or timeout — as `HTTP GET <url>: <cause>`. It indicates the request never completed at the HTTP layer, so no status code exists yet.","triggerScenarios":"Calling fetchPresetsFromURL (via the presets cache fetch) where `client.Get(url)` returns a non-nil error: unreachable host, refused connection, expired TLS cert, or the configured per-request timeout elapsing.","commonSituations":"Typo in the presets URL scheme/host; firewall or VPN blocking outbound HTTPS; corporate MITM proxy with an untrusted CA; slow network hitting the client Timeout.","solutions":["Test the exact URL manually: `curl -v <url>` and fix DNS/proxy/certificate issues it reveals.","Check the configured presets URL for typos (scheme, host, port).","If behind a proxy, set HTTPS_PROXY / trust the corporate root CA.","If timeouts recur, increase the fetch timeout parameter or move to a closer mirror of the presets source."],"exampleFix":"// before\nresp, err := client.Get(url)\nif err != nil { return nil, fmt.Errorf(\"HTTP GET %s: %w\", url, err) }\n\n// after (caller-side retry with backoff)\nvar resp *http.Response\nvar err error\nfor i := 0; i < 3; i++ {\n    resp, err = client.Get(url)\n    if err == nil { break }\n    time.Sleep(time.Duration(1<<i) * time.Second)\n}","handlingStrategy":"retry","validationCode":"u, err := url.Parse(url)\nif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") { return errors.New(\"presets URL must be absolute http(s)\") }","typeGuard":null,"tryCatchPattern":"var resp *http.Response\nvar err error\nfor attempt := 0; attempt < 3; attempt++ {\n    resp, err = client.Get(url)\n    if err == nil { break }\n    time.Sleep(time.Duration(1<<attempt) * time.Second)\n}","preventionTips":["Set a sane client Timeout and retry with exponential backoff for transient failures.","Validate the configured URL scheme/host at config load time.","Configure HTTPS_PROXY and corporate CAs explicitly in restricted networks."],"tags":["network","http","timeout","dns","go"],"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-14T05:17:10.506Z"}