{"record":{"id":"e065db0cae873cfd","repo":"chenhg5/cc-connect","slug":"dingtalk-marshal-image-message-w","errorCode":null,"errorMessage":"dingtalk: marshal image message: %w","messagePattern":"dingtalk: marshal image message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"platform/dingtalk/dingtalk.go","lineNumber":1047,"sourceCode":"\n\tslog.Debug(\"dingtalk: image uploaded\", \"media_id\", mediaID, \"size\", len(img.Data))\n\n\ttoken, err := p.getAccessToken()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: get access token: %w\", err)\n\t}\n\n\tmsgParamBytes, _ := json.Marshal(map[string]string{\"photoURL\": mediaID})\n\trequestBody := map[string]any{\n\t\t\"robotCode\": p.robotCode,\n\t\t\"userIds\":   []string{rc.senderStaffId},\n\t\t\"msgKey\":    \"sampleImageMsg\",\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 image 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 image 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 image request: %w\", err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\trespBody, _ := io.ReadAll(resp.Body)","sourceCodeStart":1029,"sourceCodeEnd":1065,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/dingtalk/dingtalk.go#L1029-L1065","documentation":"This error is returned by Platform.SendImage when json.Marshal fails on the oToMessages batchSend request body (robotCode, userIds, msgKey, msgParam). It means the image-send request could not be serialized to JSON before being POSTed to DingTalk. Because the body is assembled entirely from strings and string slices in memory, a marshal failure is a defensive guard that is effectively unreachable in normal operation.","triggerScenarios":"json.Marshal(requestBody) errors inside SendImage — only possible if a non-serializable value entered the requestBody map (channels/funcs), which the current construction (plain strings) prevents.","commonSituations":"Effectively none for library users; would only surface from a code modification that inserts dynamic values into the payload.","solutions":["Retry the operation — no user configuration or input causes this","If you modified the payload construction, revert changes that add non-JSON-serializable values","Report to maintainers with the wrapped error if it reproduces on stock code"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := p.SendImage(ctx, rctx, img); err != nil {\n    if strings.Contains(err.Error(), \"marshal image message\") {\n        slog.Warn(\"dingtalk image marshal (unexpected)\", \"err\", err)\n    }\n}","preventionTips":["Keep the oToMessages payload construction limited to plain strings/[]string","Avoid local edits that insert dynamic or non-serializable values into requestBody"],"tags":["dingtalk","json","serialization"],"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-14T05:17:10.506Z"}