{"record":{"id":"84710e2c0abd8734","repo":"Tencent/WeKnora","slug":"failed-to-execute-request-w","errorCode":null,"errorMessage":"failed to execute request: %w","messagePattern":"failed to execute request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/keenable.go","lineNumber":100,"sourceCode":"\tbodyBytes, err := json.Marshal(keenableSearchRequest{Query: query, Mode: \"pro\"})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal request: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", endpoint, bytes.NewReader(bodyBytes))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\treq.Header.Set(\"X-Keenable-Title\", keenableTitle)\n\tif p.apiKey != \"\" {\n\t\treq.Header.Set(\"X-API-Key\", p.apiKey)\n\t}\n\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\trespBody, _ := io.ReadAll(resp.Body)\n\t\tlogger.Warnf(ctx, \"[WebSearch][Keenable] API returned status %d: %s\", resp.StatusCode, string(respBody))\n\t\treturn nil, fmt.Errorf(\"keenable API returned status %d: %s\", resp.StatusCode, string(respBody))\n\t}\n\n\trespBody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read response: %w\", err)\n\t}\n\n\tvar respData keenableSearchResponse\n\tif err := json.Unmarshal(respBody, &respData); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal response: %w\", err)\n\t}","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/keenable.go#L82-L118","documentation":"The HTTP client failed to execute the Keenable search POST — p.client.Do(req) returned an error before any HTTP status was received. This wraps network-layer failures: DNS resolution, TCP connect, TLS handshake, timeouts, or context cancellation.","triggerScenarios":"p.client.Do(req) errors — unreachable host, DNS failure, connection refused, TLS error, request timeout (client has a 30s-style timeout), or ctx cancelled/deadline exceeded mid-request.","commonSituations":"Keenable host unreachable from the deployment network; egress firewall blocks the endpoint; DNS misconfig; proxy required but not configured; context deadline exceeded because upstream took too long.","solutions":["Inspect the wrapped error: connection refused/DNS means fix networking; context deadline means raise timeout or fix upstream latency.","Verify network egress and DNS for the Keenable endpoint from the host running the code (curl the endpoint).","Configure the proxy (params.ProxyURL) if the environment requires one.","Add retry with backoff for transient network errors, respecting context cancellation.","Check whether the configured base URL hostname resolves (typo in config)."],"exampleFix":"// before\nresp, err := p.client.Do(req)\nif err != nil { return nil, err }\n// after (caller side)\nresults, err := keenable.Search(ctx, query, 10, false)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        return nil, fmt.Errorf(\"keenable search timed out: %w\", err)\n    }\n    return nil, fmt.Errorf(\"search unavailable, retry later: %w\", err)\n}","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", host+\":443\", 5*time.Second)\nif err != nil { return fmt.Errorf(\"keenable endpoint unreachable before search: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"results, err := keenable.Search(ctx, q, n, false)\nif err != nil && strings.Contains(err.Error(), \"failed to execute request\") {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        // retry once with backoff\n    }\n    return nil, fmt.Errorf(\"search network failure: %w\", err)\n}","preventionTips":["Set sensible client timeouts and respect context deadlines","Retry transient network errors with exponential backoff","Verify egress firewall/DNS/proxy settings for the deployment environment","Health-check the search endpoint before serving traffic","Configure the proxy URL when operating behind a corporate proxy"],"tags":["network","http","keenable","web-search","timeout","dns"],"backgroundTag":"request-execution-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}