{"record":{"id":"4b654e8f9326eb38","repo":"Tencent/WeKnora","slug":"failed-to-execute-zhipu-request-w","errorCode":null,"errorMessage":"failed to execute Zhipu request: %w","messagePattern":"failed to execute Zhipu request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/zhipu.go","lineNumber":145,"sourceCode":"\t\tCount:        maxResults,\n\t\tContentSize:  p.contentSize,\n\t}\n\tbody, err := json.Marshal(requestBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal Zhipu request: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, p.baseURL, bytes.NewReader(body))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Zhipu request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+p.apiKey)\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tlogger.Infof(ctx, \"[WebSearch][Zhipu] query=%q maxResults=%d engine=%s\", preparedQuery, maxResults, p.searchEngine)\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute Zhipu request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\trespBody, err := readZhipuResponseBody(resp.Body)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, zhipuHTTPError(resp.StatusCode, respBody)\n\t}\n\n\tvar response zhipuSearchResponse\n\tif err := json.Unmarshal(respBody, &response); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal Zhipu response: %w\", err)\n\t}\n\tif response.Error.Message != \"\" || response.Error.Code != \"\" {\n\t\treturn nil, fmt.Errorf(\"Zhipu API error (%s): %s\", response.Error.Code, response.Error.Message)\n\t}","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/zhipu.go#L127-L163","documentation":"The Zhipu web search provider returns this error when the outbound HTTP request to the Zhipu search API fails at the transport level. The provider wraps the underlying *url.Error from http.Client.Do with %w so callers can use errors.Is/As to inspect the root cause. It means the request never completed — no HTTP status was received.","triggerScenarios":"Calling provider.Search() when the Zhipu endpoint is unreachable: DNS resolution failure, connection refused/timeout, TLS handshake failure, or a cancelled request context.","commonSituations":"No internet access or a firewall blocking api.zhipu.ai; an invalid proxy setting on the HTTP client; the request context timing out or being cancelled mid-flight; transient network blips in a container orchestrator.","solutions":["Retry the request with backoff — transport errors are often transient","Verify network/DNS connectivity to the Zhipu API host (curl -v the endpoint URL)","Check the configured timeout and whether the caller's context was cancelled or expired early","Inspect proxy environment variables (HTTP_PROXY/HTTPS_PROXY) that the default HTTP client honors"],"exampleFix":"// before\nresults, err := provider.Search(ctx, query) // panics on err==nil assumption\n// after\nresults, err := provider.Search(ctx, query)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() {\n        // retry with backoff\n    }\n    return fmt.Errorf(\"web search failed: %w\", err)\n}","handlingStrategy":"retry","validationCode":"if p.apiKey == \"\" { return errors.New(\"zhipu api key not configured\") }\n// also confirm context is alive: if ctx.Err() != nil { return ctx.Err() }","typeGuard":"func isTransportError(err error) bool { var ne net.Error; return errors.As(err, &ne) }","tryCatchPattern":"results, err := provider.Search(ctx, q)\nif err != nil {\n    var ne net.Error\n    if errors.As(err, &ne) && ne.Timeout() { return retryWithBackoff(ctx, q) }\n    return err\n}","preventionTips":["Set sane client timeouts and retry transport errors with exponential backoff","Monitor egress connectivity to the Zupu host from your deployment environment","Check proxy env vars in containerized deployments","Always pass a live (non-expired) context"],"tags":["network","http","web-search","zhipu"],"backgroundTag":"http-request-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}