{"record":{"id":"62b74a4d796f5eb4","repo":"fish2018/pansou","slug":"s-json-w-62b74a","errorCode":null,"errorMessage":"[%s] JSON序列化失败: %w","messagePattern":"\\[(.+?)\\] JSON序列化失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/xdyh/xdyh.go","lineNumber":126,"sourceCode":"\tif cached, ok := searchCache.Load(cacheKey); ok {\n\t\tif results, ok := cached.([]model.SearchResult); ok {\n\t\t\treturn results, nil\n\t\t}\n\t}\n\t\n\t// 2. 构建请求体\n\trequestBody := SearchRequest{\n\t\tKeyword:    keyword,\n\t\tSites:      nil,  // null表示搜索所有站点\n\t\tMaxWorkers: 10,   // API默认并发数\n\t\tSaveToFile: false,\n\t\tSplitLinks: true,\n\t}\n\t\n\t// 3. JSON序列化\n\tjsonData, err := json.Marshal(requestBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] JSON序列化失败: %w\", pluginName, err)\n\t}\n\t\n\t// 4. 创建带超时的上下文\n\tctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)\n\tdefer cancel()\n\t\n\t// 5. 创建请求\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", apiURL, bytes.NewBuffer(jsonData))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 创建请求失败: %w\", pluginName, err)\n\t}\n\t\n\t// 6. 设置请求头\n\tp.setRequestHeaders(req)\n\t\n\t// 7. 发送请求\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/xdyh/xdyh.go#L108-L144","documentation":"searchImpl in the xdyh plugin marshals the request struct to JSON with json.Marshal before sending the POST. Marshaling of plain struct fields virtually never fails, so this error indicates an internal problem (e.g. an unsupported type like chan/func or a cyclic reference in requestBody).","triggerScenarios":"json.Marshal on the request body returns an error — practically only if requestBody gains an unsupported field type (chan, func, complex) or a marshaler returns an error.","commonSituations":"Refactoring adds a field with an unsupported type to the request struct; custom MarshalJSON on a nested value fails.","solutions":["Inspect the wrapped error to find the offending field/type","Remove or change the unsupported field type in the request struct","Add a unit test marshaling the request body to catch regressions"],"exampleFix":"// before\ntype requestBody struct {\n    Callback func() `json:\"cb\"` // unsupported\n}\n// after\ntype requestBody struct {\n    Keyword  string `json:\"keyword\"`\n    SplitLinks bool `json:\"splitLinks\"`\n}","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(requestBody); err != nil {\n    return fmt.Errorf(\"请求体不可序列化: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"jsonData, err := json.Marshal(requestBody)\nif err != nil {\n    return nil, fmt.Errorf(\"[%s] JSON序列化失败: %w\", pluginName, err)\n}","preventionTips":["Keep request structs to JSON-safe types (string, number, bool, slice, map)","Add a marshaling unit test for the request body","Avoid custom MarshalJSON that can fail"],"tags":["json","serialization","internal"],"backgroundTag":"json-marshal-failed","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}