{"record":{"id":"5c5abd3eeda5a238","repo":"Tencent/WeKnora","slug":"failed-to-create-request-w","errorCode":null,"errorMessage":"failed to create request: %w","messagePattern":"failed to create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/baidu.go","lineNumber":112,"sourceCode":"func (p *BaiduProvider) buildRequest(ctx context.Context, query string, maxResults int) (*http.Request, error) {\n\trequestBody := baiduSearchRequest{\n\t\tMessages: []baiduMessage{\n\t\t\t{Role: \"user\", Content: query},\n\t\t},\n\t\tSearchSource: \"baidu_search_v2\",\n\t\tResourceTypeFilter: []baiduResourceTypeFilter{\n\t\t\t{Type: \"web\", TopK: maxResults},\n\t\t},\n\t}\n\n\tbodyBytes, err := json.Marshal(requestBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal request body: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", p.baseURL, bytes.NewReader(bodyBytes))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\n\treq.Header.Set(\"Authorization\", \"Bearer \"+p.apiKey)\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\n\treturn req, nil\n}\n\nfunc (p *BaiduProvider) doSearch(ctx context.Context, req *http.Request, includeDate bool) ([]*types.WebSearchResult, error) {\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 2<<20)) // 2MB limit\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/baidu.go#L94-L130","documentation":"HTTP client error in BaiduProvider.buildRequest: http.NewRequestWithContext could not construct the POST to the Baidu search endpoint after the body was marshaled. The %w wraps the net/http cause; it bubbles up through Search as a request-construction failure, prior to any network activity.","triggerScenarios":"Thrown at internal/infrastructure/web_search/baidu.go:112 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the configured Baidu baseURL is a valid absolute URL","Check whether the request context was already cancelled before Search was invoked"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}