{"record":{"id":"ecdc0343c6468bed","repo":"fish2018/pansou","slug":"w-ecdc03","errorCode":null,"errorMessage":"构造搜索参数失败: %w","messagePattern":"构造搜索参数失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/xiaokupan/xiaokupan.go","lineNumber":112,"sourceCode":"\tfunctionID := p.currentServerFunctionID()\n\tresults, err := p.searchWithFunctionID(client, keyword, functionID)\n\tif err != nil {\n\t\trefreshedID, refreshErr := p.refreshServerFunctionID(client, functionID)\n\t\tif refreshErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"[%s] 搜索失败: %v；刷新接口标识失败: %w\", p.Name(), err, refreshErr)\n\t\t}\n\t\tresults, err = p.searchWithFunctionID(client, keyword, refreshedID)\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索失败: %w\", p.Name(), err)\n\t}\n\treturn plugin.FilterResultsByKeyword(results, keyword), nil\n}\n\nfunc (p *XiaokupanPlugin) searchWithFunctionID(client *http.Client, keyword, functionID string) ([]model.SearchResult, error) {\n\tpayload, err := buildSearchPayload(keyword)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"构造搜索参数失败: %w\", err)\n\t}\n\n\tendpoint := fmt.Sprintf(\"%s/_serverFn/%s\", strings.TrimRight(p.baseURL, \"/\"), functionID)\n\tparsedEndpoint, err := url.Parse(endpoint)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"解析搜索地址失败: %w\", err)\n\t}\n\tquery := parsedEndpoint.Query()\n\tquery.Set(\"payload\", string(payload))\n\tparsedEndpoint.RawQuery = query.Encode()\n\n\tctx, cancel := context.WithTimeout(context.Background(), requestTimeout)\n\tdefer cancel()\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, parsedEndpoint.String(), nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建搜索请求失败: %w\", err)\n\t}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/xiaokupan/xiaokupan.go#L94-L130","documentation":"Wraps an error from buildSearchPayload, which JSON-marshals the fixed seroval payload map for the search keyword. In practice stdjson.Marshal of this map[string]interface{} structure essentially never fails (no channels/funcs/cyclic data), so this error is defensive and indicates a marshaling failure of the keyword-containing payload structure.","triggerScenarios":"json.Marshal fails while serializing the payload map in buildSearchPayload — only possible if the payload structure or keyword data contains an unsupported type (e.g. NaN/Inf float, channel, func, or cyclic reference injected via a modified keyword path).","commonSituations":"Practically never hit by users; would appear only after a code change introduced an unsupported value into the payload map, or if keyword handling started embedding non-JSON-serializable data.","solutions":["Inspect the wrapped json.Marshal error type (e.g. *json.UnsupportedTypeError) to find the offending value","Verify the keyword passed to buildSearchPayload is a plain string (cleanText output)","If NaN/Inf floats were introduced, sanitize them before marshaling","Upgrade/patch the plugin if a recent change altered the payload structure"],"exampleFix":"// before\npayload := map[string]interface{}{...}\nreturn stdjson.Marshal(payload)\n// after: fail fast with context on which field broke\nb, err := stdjson.Marshal(payload)\nif err != nil {\n    return nil, fmt.Errorf(\"marshal search payload: %w\", err)\n}\nreturn b, nil","handlingStrategy":"validation","validationCode":"func keywordIsSerializable(kw string) bool {\n    _, err := json.Marshal(map[string]interface{}{\"query\": kw})\n    return err == nil\n}\nif !keywordIsSerializable(keyword) { return errors.New(\"keyword produces non-serializable payload\") }","typeGuard":"func isPlainString(v interface{}) bool { _, ok := v.(string); return ok }","tryCatchPattern":"var typeErr *json.UnsupportedTypeError\nif errors.As(err, &typeErr) {\n    log.Printf(\"payload field %s is not JSON-serializable\", typeErr.Value)\n}","preventionTips":["Keep the payload map limited to JSON-native types (string, int, map, slice)","Sanitize keyword input before passing it into payload construction","Add a unit test marshaling buildSearchPayload output for representative keywords"],"tags":["json","serialization","search"],"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"}