{"record":{"id":"f7581255a5bb14de","repo":"Tencent/WeKnora","slug":"failed-to-marshal-request-body-w-f75812","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/ollama.go","lineNumber":96,"sourceCode":"\t}\n\tresults, err := p.doSearch(ctx, req)\n\tif err != nil {\n\t\tlogger.Warnf(ctx, \"[WebSearch][Ollama] failed: %v\", err)\n\t\treturn nil, err\n\t}\n\tlogger.Infof(ctx, \"[WebSearch][Ollama] returned %d results\", len(results))\n\treturn results, nil\n}\n\nfunc (p *OllamaProvider) buildRequest(ctx context.Context, query string, maxResults int) (*http.Request, error) {\n\trequestBody := map[string]interface{}{\n\t\t\"query\":       query,\n\t\t\"max_results\": maxResults,\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\treq.Header.Set(\"User-Agent\", defaultUserAgentHeader)\n\n\treturn req, nil\n}\n\nfunc (p *OllamaProvider) doSearch(ctx context.Context, req *http.Request) ([]*types.WebSearchResult, error) {\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/ollama.go#L78-L114","documentation":"Returned by buildRequest when json.Marshal of the {query, max_results} map fails. With these plain value types this is effectively a defensive guard; it could only fire via invalid UTF-8 in the query or a future change to the payload type.","triggerScenarios":"Thrown at internal/infrastructure/web_search/ollama.go:96 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Sanitize the query string (valid UTF-8) before searching","Review changes to the request payload if this starts firing"],"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"}