{"record":{"id":"13e074d431e117d9","repo":"Tencent/WeKnora","slug":"marshal-payload-w","errorCode":null,"errorMessage":"marshal payload: %w","messagePattern":"marshal payload: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/infrastructure/docparser/mineru_cloud_converter.go","lineNumber":129,"sourceCode":"\nfunc (c *MinerUCloudReader) applyUploadURLs(ctx context.Context, fileName, ext string) (string, string, error) {\n\tmodelVersion := c.model\n\tif strings.ToLower(ext) == \".html\" {\n\t\tmodelVersion = \"MinerU-HTML\"\n\t}\n\n\tpayload := map[string]interface{}{\n\t\t\"files\":          []map[string]string{{\"name\": fileName, \"data_id\": uuid.New().String()}},\n\t\t\"model_version\":  modelVersion,\n\t\t\"is_ocr\":         c.ocrEnable,\n\t\t\"enable_formula\": c.formulaEnable,\n\t\t\"enable_table\":   c.tableEnable,\n\t\t\"language\":       c.language,\n\t}\n\n\tbody, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"marshal payload: %w\", err)\n\t}\n\n\thttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+\"/file-urls/batch\", bytes.NewReader(body))\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"create request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Authorization\", \"Bearer \"+c.apiKey)\n\thttpReq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tclient := utils.NewSSRFSafeHTTPClient(utils.SSRFSafeHTTPClientConfig{Timeout: 30 * time.Second, MaxRedirects: 5})\n\tresp, err := client.Do(httpReq)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"HTTP request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\trespBody, _ := io.ReadAll(resp.Body)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/mineru_cloud_converter.go#L111-L147","documentation":"applyUploadURLs marshals the batch request payload (filename, extension, table/language options) to JSON before POSTing it; a json.Marshal failure is wrapped as \"marshal payload: %w\". With a plain map of strings/bools this is nearly impossible at runtime, but the library defends the error path anyway.","triggerScenarios":"Read -> applyUploadURLs where json.Marshal of the payload map returns an error — practically only if a payload value becomes a non-JSON-serializable type (channel, func, or unsupported custom type) via configuration.","commonSituations":"Custom configuration wiring injecting a non-serializable value (e.g. a func or channel) into the converter's option fields; misuse of the struct by embedding unsupported types; essentially never triggered by standard string/bool config.","solutions":["Inspect the wrapped cause to identify which payload field failed to serialize.","Check how the converter's options (tableEnable, language, etc.) are populated; ensure only JSON-compatible types (string, bool, number) are set.","Fix the configuration wiring so no func/channel/unsupported type reaches the payload.","If caused by a library bug, report/patch — normally this path cannot fail with standard inputs."],"exampleFix":"// before: non-serializable value in payload options\nc.language = func() string { return \"en\" } // json.Marshal fails\n// after\nif l, ok := langOption.(string); ok { c.language = l } else { c.language = \"en\" }","handlingStrategy":"validation","validationCode":"payload := map[string]interface{}{\"enable_table\": tableEnable, \"language\": language}\nif _, err := json.Marshal(payload); err != nil {\n    return fmt.Errorf(\"converter options are not JSON-serializable: %w\", err)\n}","typeGuard":"func jsonSerializable(v interface{}) bool {\n    b, err := json.Marshal(v)\n    return err == nil && b != nil\n}","tryCatchPattern":"res, err := converter.Read(ctx, req)\nif err != nil {\n    if strings.Contains(err.Error(), \"marshal payload\") {\n        return fmt.Errorf(\"mineru converter options contain a non-serializable value: %w\", err)\n    }\n    return err\n}","preventionTips":["Populate converter options only with JSON-compatible types (string, bool, number).","Add a startup self-test that marshals the configured payload once.","Avoid injecting dynamic/computed values (funcs, channels) into option fields."],"tags":["json","marshal","configuration"],"backgroundTag":"json-marshal-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}