{"record":{"id":"2f7a4e0ed2451716","repo":"Tencent/WeKnora","slug":"failed-to-perform-request-w","errorCode":null,"errorMessage":"failed to perform request: %w","messagePattern":"failed to perform request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/duckduckgo.go","lineNumber":95,"sourceCode":"\treqURL := baseURL + \"?\" + params.Encode()\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", reqURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\treq.Header.Set(\n\t\t\"User-Agent\",\n\t\t\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\",\n\t)\n\n\tcurlCommand := fmt.Sprintf(\n\t\t\"curl -X GET '%s' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'\",\n\t\treq.URL.String(),\n\t)\n\tlogger.Infof(ctx, \"Curl of request: %s\", secutils.SanitizeForLog(curlCommand))\n\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to perform request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {\n\t\treturn nil, fmt.Errorf(\"duckduckgo HTML returned status %d\", resp.StatusCode)\n\t}\n\n\tdoc, err := goquery.NewDocumentFromReader(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse HTML: %w\", err)\n\t}\n\n\tresults := make([]*types.WebSearchResult, 0, maxResults)\n\tdoc.Find(\".web-result\").Each(func(i int, s *goquery.Selection) {\n\t\tif len(results) >= maxResults {\n\t\t\treturn\n\t\t}\n\t\ttitleNode := s.Find(\".result__a\")","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/duckduckgo.go#L77-L113","documentation":"The HTTP client failed to execute the DuckDuckGo HTML search request in searchHTML (transport-level failure), wrapped as \"failed to perform request\". No response was received, so this is a connection/TLS/DNS/context problem rather than a bad status.","triggerScenarios":"client.Do(req) returns an error: DNS resolution failure, connection refused/timeout, TLS handshake failure, or ctx cancellation mid-request.","commonSituations":"No internet access or blocked egress (firewall, sandboxed CI); DuckDuckGo refusing datacenter IPs at TLS level; requests without a timeout hanging until the context deadline.","solutions":["Check the wrapped error class: context.DeadlineExceeded -> increase timeout or retry; connection refused -> verify network/proxy.","Confirm outbound HTTPS to html.duckduckgo.com is allowed from your host.","Configure an HTTP proxy on p.client if running behind corporate egress.","Add retry with backoff for transient transport errors."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\ndefer cancel()\n// pass ctx into the search call","typeGuard":"func isTransportErr(err error) bool {\n    if err == nil { return false }\n    var ne net.Error\n    return errors.As(err, &ne) || strings.Contains(err.Error(), \"failed to perform request\")\n}","tryCatchPattern":"var lastErr error\nfor attempt := 0; attempt < 3; attempt++ {\n    results, err := ddg.Search(ctx, query, 10, false)\n    if err == nil { return results, nil }\n    lastErr = err\n    if strings.Contains(err.Error(), \"failed to perform request\") {\n        time.Sleep(backoff(attempt)) // transport error: retry\n        continue\n    }\n    break // non-transport: don't retry\n}","preventionTips":["Set sane client timeouts (connect + total) on the HTTP client.","Verify egress/firewall rules for duckduckgo.com in each environment.","Use errors.As with net.Error to distinguish timeouts from hard failures.","Configure proxy settings where corporate egress is required."],"tags":["network","http-client","web-search","go"],"backgroundTag":"http-request-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}