{"record":{"id":"07ed0672b03919cc","repo":"fish2018/pansou","slug":"marshal-request-failed-page-d-w","errorCode":null,"errorMessage":"marshal request failed (page %d): %w","messagePattern":"marshal request failed \\(page (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/hunhepan/hunhepan.go","lineNumber":202,"sourceCode":"\t\t\t\t\"page\":         pageNum,\n\t\t\t\t\"q\":            keyword,\n\t\t\t\t\"user\":         \"\",\n\t\t\t\t\"exact\":        false,\n\t\t\t\t\"format\":       []string{},\n\t\t\t\t\"share_time\":   \"\",\n\t\t\t\t\"size\":         DefaultPageSize,\n\t\t\t\t\"type\":         \"\",\n\t\t\t\t\"exclude_user\": []string{},\n\t\t\t\t\"adv_params\": map[string]interface{}{\n\t\t\t\t\t\"wechat_pwd\": \"\",\n\t\t\t\t\t\"platform\":   \"pc\",\n\t\t\t\t},\n\t\t\t}\n\n\t\t\tjsonData, err := json.Marshal(reqBody)\n\t\t\tif err != nil {\n\t\t\t\tdebugLog(\"序列化请求失败 (page %d): %v\", pageNum, err)\n\t\t\t\terrChan <- fmt.Errorf(\"marshal request failed (page %d): %w\", pageNum, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tdebugLog(\"发送请求到 %s (page %d): %s\", apiURL, pageNum, string(jsonData))\n\n\t\t\treq, err := http.NewRequest(\"POST\", apiURL, bytes.NewBuffer(jsonData))\n\t\t\tif err != nil {\n\t\t\t\tdebugLog(\"创建请求失败 (page %d): %v\", pageNum, err)\n\t\t\t\terrChan <- fmt.Errorf(\"create request failed (page %d): %w\", pageNum, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\t\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\")\n\t\t\treq.Header.Set(\"Accept\", \"application/json, text/plain, */*\")\n\t\t\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\n\t\t\t// 根据不同的API设置不同的Referer","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/hunhepan/hunhepan.go#L184-L220","documentation":"In the hunhepan plugin's paginated request builder, json.Marshal(reqBody) for a page failed. The marshal of a plain map/struct should rarely fail, so this usually indicates an unsupported value (e.g. a channel, func, or cyclic structure) snuck into reqBody.","triggerScenarios":"json.Marshal(reqBody) returns an error while building the POST body for pageNum of a paged search; the error is pushed to errChan with the page number.","commonSituations":"A field of unsupported type (chan/func/complex) added to reqBody, a cyclic reference, or a custom json.Marshaler returning an error — rare, typically a code regression rather than runtime data.","solutions":["Inspect the wrapped error message for the unsupported type name","Check recently changed fields in reqBody for non-JSON-serializable values","Replace unsupported values with serializable equivalents (string/number)","Pre-validate reqBody types in tests to catch regressions early"],"exampleFix":"// before\njsonData, err := json.Marshal(reqBody)\nif err != nil {\n\terrChan <- fmt.Errorf(\"marshal request failed (page %d): %w\", pageNum, err)\n\treturn\n}\n// after\njsonData, err := json.Marshal(reqBody)\nif err != nil {\n\terrChan <- fmt.Errorf(\"marshal request failed (page %d): %w (reqBody=%+v)\", pageNum, err, reqBody)\n\treturn\n}","handlingStrategy":"validation","validationCode":"if err := json.Valid(mustMarshal(reqBody)); !err {\n\t// request body not serializable; fix reqBody types before calling\n}\nfunc mustMarshal(v interface{}) []byte {\n\tb, _ := json.Marshal(v)\n\treturn b\n}","typeGuard":null,"tryCatchPattern":"// caller side\nif err != nil && strings.Contains(err.Error(), \"marshal request failed\") {\n\tvar page int\n\tfmt.Sscanf(err.Error(), \"marshal request failed (page %d)\", &page)\n\tlog.Printf(\"page %d body unserializable: %v\", page, err)\n}","preventionTips":["Keep reqBody limited to JSON-safe types (string, number, bool, slice, map)","Add unit tests marshaling the request body for each page shape","Check json.Marshaler implementations on custom types for error returns","Log the offending reqBody when this error fires to find the bad field"],"tags":["json","serialization","pagination"],"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"}