{"record":{"id":"d1c59ce6b932e26f","repo":"chenhg5/cc-connect","slug":"dingtalk-marshal-file-message-w","errorCode":null,"errorMessage":"dingtalk: marshal file message: %w","messagePattern":"dingtalk: marshal file message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/dingtalk/dingtalk.go","lineNumber":1142,"sourceCode":"\tif idx := strings.LastIndex(name, \".\"); idx >= 0 {\n\t\text = name[idx+1:]\n\t}\n\n\tmsgParamBytes, _ := json.Marshal(map[string]string{\n\t\t\"mediaId\":  mediaID,\n\t\t\"fileName\": name,\n\t\t\"fileType\": ext,\n\t})\n\trequestBody := map[string]any{\n\t\t\"robotCode\": p.robotCode,\n\t\t\"userIds\":   []string{rc.senderStaffId},\n\t\t\"msgKey\":    \"sampleFile\",\n\t\t\"msgParam\":  string(msgParamBytes),\n\t}\n\n\tbody, err := json.Marshal(requestBody)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: marshal file message: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost,\n\t\t\"https://api.dingtalk.com/v1.0/robot/oToMessages/batchSend\",\n\t\tbytes.NewReader(body))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: create file request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"x-acs-dingtalk-access-token\", token)\n\n\tresp, err := p.httpClient.Do(req)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: send file request: %w\", err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\trespBody, _ := io.ReadAll(resp.Body)","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/dingtalk/dingtalk.go#L1124-L1160","documentation":"SendFile failed to JSON-marshal the request body for the oToMessages batchSend call. This is nearly impossible in practice since the body is built from simple string fields, and would indicate an internal bug (e.g. a field type json cannot serialize, like a channel or func) or memory exhaustion.","triggerScenarios":"Internal struct contains an unserializable value; extreme low-memory conditions; corrupted build with a wrong field type in requestBody.","commonSituations":"Only seen after modifying the platform code and adding a non-serializable field to requestBody; otherwise effectively never.","solutions":["Inspect the struct being marshalled for json-unsupported types (chan, func, cyclic refs)","Rebuild from a clean checkout to rule out local edits","Check host memory availability if OOM symptoms accompany the error","If you added fields to requestBody, ensure they are JSON-serializable types"],"exampleFix":"// before\nrequestBody[\"callback\"] = someFunc // not JSON serializable\n// after\nrequestBody[\"callbackName\"] = callbackFuncName // string instead","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := p.SendFile(ctx, rc, file); err != nil {\n    if strings.Contains(err.Error(), \"marshal file message\") {\n        // internal serialization bug — report with stack trace\n        slog.Error(\"dingtalk: non-serializable request body\", \"err\", err)\n    }\n    return err\n}","preventionTips":["Keep request-body structs limited to JSON-serializable types (string, number, bool)","Run go vet and marshal unit tests when touching message-building code","If this error appears without local code changes, rebuild from a clean release tag"],"tags":["json","serialization","dingtalk"],"backgroundTag":"json-marshal-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}