{"record":{"id":"bb40b0266bcc81b5","repo":"Tencent/WeKnora","slug":"failed-to-marshal-request-body-w","errorCode":null,"errorMessage":"failed to marshal request body: %w","messagePattern":"failed to marshal request body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/baidu.go","lineNumber":107,"sourceCode":"\t}\n\tlogger.Infof(ctx, \"[WebSearch][Baidu] returned %d results\", len(results))\n\treturn results, nil\n}\n\nfunc (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}","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/baidu.go#L89-L125","documentation":"Returned by buildRequest when json.Marshal of the baiduSearchRequest body fails. The struct holds only strings, ints, and slices, so this is effectively unreachable unless the struct gains unmarshalable fields; it guards the request-construction path.","triggerScenarios":"Thrown at internal/infrastructure/web_search/baidu.go:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error if it ever fires","Review recent changes to baiduSearchRequest for unmarshalable fields (channels, funcs, invalid UTF-8 in content)"],"exampleFix":null,"handlingStrategy":"try-catch","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"}