{"record":{"id":"6d9de03175b509d4","repo":"chenhg5/cc-connect","slug":"read-body-from-s-w","errorCode":null,"errorMessage":"read body from %s: %w","messagePattern":"read body from (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/provider_presets.go","lineNumber":150,"sourceCode":"\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}\n","sourceCodeStart":132,"sourceCodeEnd":159,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/provider_presets.go#L132-L159","documentation":"After a successful 200 response, the body is read with a 1 MiB cap (`io.LimitReader(resp.Body, 1<<20)`). This error wraps any I/O failure while reading the response stream — the connection dropped mid-transfer, or an intermediate proxy truncated the response.","triggerScenarios":"Calling fetchPresetsFromURL where `io.ReadAll` on the limited body returns an error: server resets the connection mid-body, read timeout firing during body transfer, or proxy interruption.","commonSituations":"Flaky mobile/satellite links; load balancers with aggressive idle timeouts; proxies that kill long-running body streams; extremely large responses hitting infrastructure limits and getting cut off.","solutions":["Retry the fetch — transient connection resets usually succeed on a second attempt.","Check for proxies/load balancers between the client and server and raise their body/idle timeouts.","Serve the presets from a more reliable host or CDN.","Fall back to the stale cache (`c.data`) when a fresh fetch fails mid-body, which the fetch caller already does."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"body, err := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\nif err != nil {\n    slog.Warn(\"presets body read failed, will retry/fall back\", \"url\", url, \"error\", err)\n    return retryOrStale()\n}","preventionTips":["Always retry transient mid-body read failures.","Set the http.Client Timeout large enough for slow links so reads are not cut off.","Prefer hosting presets on a reliable CDN."],"tags":["network","http","io","go"],"backgroundTag":"network-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"}