{"record":{"id":"35d9fcda757d67bb","repo":"fish2018/pansou","slug":"http-w","errorCode":null,"errorMessage":"HTTP请求失败: %w","messagePattern":"HTTP请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/cyg/cyg.go","lineNumber":149,"sourceCode":"// fetchSearchResults 获取搜索结果列表\nfunc (p *CygPlugin) fetchSearchResults(client *http.Client, searchURL string) ([]CygPost, error) {\n\t// 创建带超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\n\tdefer cancel()\n\n\t// 创建请求对象\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", searchURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建请求失败: %w\", err)\n\t}\n\n\t// 设置请求头\n\tp.setRequestHeaders(req)\n\n\t// 发送请求\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"HTTP请求失败: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\t// 检查状态码\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"HTTP错误状态码: %d\", resp.StatusCode)\n\t}\n\n\t// 解析响应\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"读取响应失败: %w\", err)\n\t}\n\n\tvar posts []CygPost\n\tif err := json.Unmarshal(body, &posts); err != nil {\n\t\treturn nil, fmt.Errorf(\"JSON解析失败: %w\", err)\n\t}","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/cyg/cyg.go#L131-L167","documentation":"In fetchSearchResults, the HTTP request executed via doRequestWithRetry returned a transport-level error (connection failure, timeout, TLS error, context deadline). The error wraps the underlying cause. Even with retries, persistent network problems surface here.","triggerScenarios":"searchImpl triggers a search and p.doRequestWithRetry exhausts its attempts — DNS failure, connection refused/reset, TLS handshake failure, or the 30-second context timeout expiring.","commonSituations":"Upstream host unreachable or DNS broken; firewall/proxy blocking outbound requests; site slow enough that the 30s context times out; server intermittently resetting connections so all retries fail.","solutions":["Check basic connectivity: curl -v the search URL from the same host.","Increase the 30-second context timeout if the upstream is slow, or tune retry count/backoff in doRequestWithRetry.","Verify DNS resolution and any proxy environment variables (HTTP_PROXY/HTTPS_PROXY) are correct.","Inspect the wrapped error for the specific cause (timeout vs refused vs TLS) and address accordingly."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"results, err := plugin.SearchWithResult(ctx, opts)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        // increase timeout or retry with backoff\n    }\n}","preventionTips":["Confirm outbound connectivity/DNS to the upstream host from the deployment environment","Keep the 30s context timeout generous or make it configurable for slow upstreams","Check proxy env vars (HTTP_PROXY/HTTPS_PROXY) don't break direct connections","Rely on the plugin's retry loop but cap total latency with your own deadline"],"tags":["http","network","timeout","go"],"backgroundTag":"network-request-failed","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}