chenhg5/cc-connect · info
dingtalk: marshal image message: %w
Error message
dingtalk: marshal image message: %w
What it means
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.
Source
Thrown at platform/dingtalk/dingtalk.go:1047
slog.Debug("dingtalk: image uploaded", "media_id", mediaID, "size", len(img.Data))
token, err := p.getAccessToken()
if err != nil {
return fmt.Errorf("dingtalk: get access token: %w", err)
}
msgParamBytes, _ := json.Marshal(map[string]string{"photoURL": mediaID})
requestBody := map[string]any{
"robotCode": p.robotCode,
"userIds": []string{rc.senderStaffId},
"msgKey": "sampleImageMsg",
"msgParam": string(msgParamBytes),
}
body, err := json.Marshal(requestBody)
if err != nil {
return fmt.Errorf("dingtalk: marshal image message: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost,
"https://api.dingtalk.com/v1.0/robot/oToMessages/batchSend",
bytes.NewReader(body))
if err != nil {
return fmt.Errorf("dingtalk: create image request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-acs-dingtalk-access-token", token)
resp, err := p.httpClient.Do(req)
if err != nil {
return fmt.Errorf("dingtalk: send image request: %w", err)
}
defer func() { _ = resp.Body.Close() }()
respBody, _ := io.ReadAll(resp.Body)View on GitHub (pinned to 4000b2338a)
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
Defensive patterns
Strategy: try-catch
Try / catch
if err := p.SendImage(ctx, rctx, img); err != nil {
if strings.Contains(err.Error(), "marshal image message") {
slog.Warn("dingtalk image marshal (unexpected)", "err", err)
}
} Prevention
- Keep the oToMessages payload construction limited to plain strings/[]string
- Avoid local edits that insert dynamic or non-serializable values into requestBody
When it happens
Trigger: 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.
Common situations: Effectively none for library users; would only surface from a code modification that inserts dynamic values into the payload.
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
- marshal payload: %w
- marshal request: %w
- dingtalk: marshal emotion request: %w
- dingtalk: marshal file message: %w
- dingtalk: marshal proactive message: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/e065db0cae873cfd.
Report an issue: GitHub.