fish2018/pansou · error
marshal request failed
Error message
marshal request failed: %w
What it means
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).
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
Example fix
// before "size": DefaultPageSize, // changed to a non-serializable value -> marshal error // after "size": DefaultPageSize, // keep as int constant; ensure all fields are JSON-serializable
Defensive patterns
Strategy: validation
Validate before calling
if _, err := json.Marshal(reqBody); err != nil {
log.Printf("request body not serializable: %v", err)
} Try / catch
if err != nil {
return nil, fmt.Errorf("marshal request failed: %w", err)
}
// guard: unit-test reqBody serialization in CI
func TestReqBodySerializable(t *testing.T) {
if _, err := json.Marshal(buildReqBody(1, "kw")); err != nil {
t.Fatal(err)
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/13c8718c6efe3dea.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/melost/melost.go:152
"share_time": "",
"share_year": "",
"size": DefaultPageSize,
"order": "",
"type": "",
"search_ticket": "",
"exclude_user": []string{},
"adv_params": map[string]interface{}{
"wechat_pwd": "",
"search_code": "",
"platform": "pc",
"fp_data": "",
"automated": DefaultAutomated,
},
}
jsonData, err := json.Marshal(reqBody)
if err != nil {
return nil, fmt.Errorf("marshal request failed: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancel()
req, err := http.NewRequestWithContext(ctx, "POST", MelostSearchAPI, bytes.NewBuffer(jsonData))
if err != nil {
return nil, fmt.Errorf("create request failed: %w", err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json, text/plain, */*")
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.Header.Set("Origin", "https://www.melost.cn")
req.Header.Set("Referer", DefaultReferer)
req.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")
resp, err := client.Do(req)View on GitHub (pinned to beaa561337)