{"record":{"id":"2a760287ec152707","repo":"Tencent/WeKnora","slug":"failed-to-marshal-zhipu-request-w","errorCode":null,"errorMessage":"failed to marshal Zhipu request: %w","messagePattern":"failed to marshal Zhipu request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/zhipu.go","lineNumber":132,"sourceCode":"\t\tlogger.Infof(ctx, \"[WebSearch][Zhipu] truncated query to %d characters\", maxZhipuQueryRunes)\n\t}\n\tif maxResults <= 0 {\n\t\tmaxResults = defaultZhipuResults\n\t}\n\tif maxResults > maxZhipuResults {\n\t\tmaxResults = maxZhipuResults\n\t}\n\n\trequestBody := zhipuSearchRequest{\n\t\tSearchQuery:  preparedQuery,\n\t\tSearchEngine: p.searchEngine,\n\t\tSearchIntent: false,\n\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 {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/zhipu.go#L114-L150","documentation":"json.Marshal failed while serializing the Zhipu web search request body. In practice this is nearly impossible with the plain request struct (all string/int/bool fields), so it usually indicates a defective custom struct or an unexpected marshalling environment issue.","triggerScenarios":"Calling provider.Search when json.Marshal of the requestBody struct returns an error — theoretically only if the struct gains unsupported field types (e.g. a channel, func, or a MarshalJSON method that errors).","commonSituations":"Custom forks adding fields with unmarshalable types (channels, funcs, cycles), custom MarshalJSON implementations returning errors, or vendored code drift.","solutions":["Inspect the wrapped error to identify which field cannot be marshalled.","Remove or fix struct fields with unmarshalable types (channel, func, circular pointers).","Check any custom MarshalJSON methods on requestBody or its fields for error paths.","Compare against upstream zhipu.go — this should not occur with the stock struct."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// stock struct cannot fail; only needed if you customize the request type:\nif _, err := json.Marshal(myRequestBody); err != nil {\n    return fmt.Errorf(\"request body not marshalable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"results, err := provider.Search(ctx, q, 5, false)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal Zhipu request\") {\n        return fmt.Errorf(\"unexpected marshal failure; check custom request fields: %w\", err)\n    }\n    return err\n}","preventionTips":["Do not add channels/funcs/cyclic references to request structs","Avoid error-returning custom MarshalJSON on request types","Keep the request struct identical to upstream","Add a unit test marshalling the request body"],"tags":["json","serialization","zhipu","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"}