{"record":{"id":"71013929d2920d9c","repo":"Tencent/WeKnora","slug":"failed-to-marshal-request-w","errorCode":null,"errorMessage":"failed to marshal request: %w","messagePattern":"failed to marshal request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/keenable.go","lineNumber":84,"sourceCode":") ([]*types.WebSearchResult, error) {\n\tif len(query) == 0 {\n\t\treturn nil, fmt.Errorf(\"query is empty\")\n\t}\n\tif maxResults <= 0 {\n\t\tmaxResults = defaultKeenableResults\n\t}\n\n\t// Keyless by default; a configured key switches to the authenticated path.\n\tpath := \"/v1/search/public\"\n\tif p.apiKey != \"\" {\n\t\tpath = \"/v1/search\"\n\t}\n\tendpoint := p.baseURL + path\n\tlogger.Infof(ctx, \"[WebSearch][Keenable] query=%q maxResults=%d url=%s\", query, maxResults, endpoint)\n\n\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()","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/keenable.go#L66-L102","documentation":"KeenableProvider.Search failed to serialize its keenableSearchRequest (Query + Mode \"pro\") to JSON before building the HTTP request. Because the struct contains only basic types this error is practically unreachable unless the struct gains unsupported fields (e.g. channels, funcs) or a custom marshaller misbehaves.","triggerScenarios":"json.Marshal(keenableSearchRequest{...}) returns an error — normally impossible for plain string/int fields; possible after adding fields of unsupported types (chan, func, cyclic pointers).","commonSituations":"A developer extended keenableSearchRequest with an unsupported field type; a custom MarshalJSON returns an error; corrupted build with a stale struct definition.","solutions":["Inspect the wrapped error — it names the unsupported value/type in the request struct.","Remove or replace fields of types json.Marshal cannot encode (chan, func, complex).","If a custom MarshalJSON exists, fix it to return valid JSON or nil error.","Rebuild the binary to ensure the struct definition matches expectations."],"exampleFix":"// before\ntype keenableSearchRequest struct {\n    Query string\n    Mode  string\n    Callback func() // unsupported by json.Marshal\n}\n// after\ntype keenableSearchRequest struct {\n    Query string `json:\"query\"`\n    Mode  string `json:\"mode\"`\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to marshal request\") {\n    log.Errorf(\"keenable request struct not JSON-serializable: %v\", err)\n    return nil, fmt.Errorf(\"internal error building keenable request: %w\", err)\n}","preventionTips":["Keep request structs limited to JSON-encodable field types","Add struct tags and round-trip tests (marshal/unmarshal) for request types","Avoid custom MarshalJSON unless necessary; test it if used","Treat any occurrence as a build/code defect, not a runtime config issue"],"tags":["json","marshal","keenable","web-search"],"backgroundTag":"json-marshal-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}