{"record":{"id":"13c8718c6efe3dea","repo":"fish2018/pansou","slug":"marshal-request-failed-w-13c871","errorCode":null,"errorMessage":"marshal request failed: %w","messagePattern":"marshal request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/melost/melost.go","lineNumber":152,"sourceCode":"\t\t\"share_time\":    \"\",\n\t\t\"share_year\":    \"\",\n\t\t\"size\":          DefaultPageSize,\n\t\t\"order\":         \"\",\n\t\t\"type\":          \"\",\n\t\t\"search_ticket\": \"\",\n\t\t\"exclude_user\":  []string{},\n\t\t\"adv_params\": map[string]interface{}{\n\t\t\t\"wechat_pwd\":  \"\",\n\t\t\t\"search_code\": \"\",\n\t\t\t\"platform\":    \"pc\",\n\t\t\t\"fp_data\":     \"\",\n\t\t\t\"automated\":   DefaultAutomated,\n\t\t},\n\t}\n\n\tjsonData, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"marshal request failed: %w\", err)\n\t}\n\n\tctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)\n\tdefer cancel()\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", MelostSearchAPI, bytes.NewBuffer(jsonData))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create request failed: %w\", err)\n\t}\n\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Accept\", \"application/json, text/plain, */*\")\n\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\treq.Header.Set(\"Origin\", \"https://www.melost.cn\")\n\treq.Header.Set(\"Referer\", DefaultReferer)\n\treq.Header.Set(\"User-Agent\", \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36\")\n\n\tresp, err := client.Do(req)","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/melost/melost.go#L134-L170","documentation":"searchPage marshals its request body (a map[string]interface{} of search parameters) with json.Marshal before POSTing to MelostSearchAPI; a marshal failure returns \"marshal request failed: %w\". In practice this is nearly impossible for this request shape since all values are JSON-serializable types (string, int, bool, []string, nested maps).","triggerScenarios":"json.Marshal(reqBody) fails, which would require an unsupported value type in reqBody — e.g. if ext-driven or constant values were changed to include channels, funcs, or NaN/Inf floats.","commonSituations":"Only occurs after a code modification: someone replaced a constant (DefaultPageSize, DefaultAutomated) or field with a non-serializable value, or added a custom type without a MarshalJSON method.","solutions":["Inspect the wrapped error message; json.Marshal errors name the unsupported type","Check recent changes to reqBody fields in searchPage for non-JSON types","Restore JSON-serializable types (string/int/bool/slice/map) for all reqBody values","Add a unit test marshaling reqBody to catch regressions"],"exampleFix":"// before\n\"size\": DefaultPageSize, // changed to a non-serializable value -> marshal error\n// after\n\"size\": DefaultPageSize, // keep as int constant; ensure all fields are JSON-serializable","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(reqBody); err != nil {\n\tlog.Printf(\"request body not serializable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n\treturn nil, fmt.Errorf(\"marshal request failed: %w\", err)\n}\n// guard: unit-test reqBody serialization in CI\nfunc TestReqBodySerializable(t *testing.T) {\n\tif _, err := json.Marshal(buildReqBody(1, \"kw\")); err != nil {\n\t\tt.Fatal(err)\n\t}\n}","preventionTips":["Keep reqBody values restricted to JSON-native types","Add a CI unit test that marshals the exact request body","Review any code change introducing custom types into reqBody","Prefer typed request structs over map[string]interface{} for compile-time safety"],"tags":["json","serialization","go"],"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"}