chenhg5/cc-connect · info
dingtalk: marshal emotion request: %w
Error message
dingtalk: marshal emotion request: %w
What it means
This error is returned by sendEmotion when json.Marshal fails on the emotion request payload before posting to DingTalk's robot emotion API. It indicates the emotion request body could not be serialized to JSON. In practice this is nearly unreachable: the requestBody is a plain map of strings built in-memory, so a marshal failure signals a genuinely unexpected serialization problem.
Source
Thrown at platform/dingtalk/dingtalk.go:949
if recall {
path = "/v1.0/robot/emotion/recall"
}
requestBody := dingtalkEmotionRequest{
RobotCode: p.robotCode,
OpenMsgID: rc.messageID,
OpenConversationID: rc.conversationId,
EmotionType: 2,
EmotionName: emoji,
TextEmotion: dingtalkTextEmotion{
EmotionID: customTextEmotionID,
EmotionName: emoji,
Text: emoji,
BackgroundID: customTextEmotionBackground,
},
}
body, err := json.Marshal(requestBody)
if err != nil {
return fmt.Errorf("dingtalk: marshal emotion request: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.dingtalk.com"+path, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("dingtalk: create emotion 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: emotion request: %w", err)
}
defer func() { _ = resp.Body.Close() }()
respBody, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("dingtalk: emotion returned status %d: %s", resp.StatusCode, string(respBody))View on GitHub (pinned to 4000b2338a)
Solutions
- Retry the operation; this is not caused by user input or configuration
- If reproducible, inspect the payload values passed to sendEmotion and report the exact emoji/reply data to the maintainers
- Check the Go version and dingtalk module version for known encoding/json regressions
Defensive patterns
Strategy: try-catch
Try / catch
if err := p.AddDoneReaction(ctx, msg); err != nil {
if strings.Contains(err.Error(), "marshal emotion request") {
// unreachable in practice; log and continue
slog.Warn("dingtalk emotion marshal (unexpected)", "err", err)
}
} Prevention
- Only construct emotion payloads via the library's own sendEmotion path
- Avoid local modifications that insert dynamic values into the request map
When it happens
Trigger: json.Marshal(requestBody) returns an error inside sendEmotion for the /v1.0/robot/emotion/reply or /robot/emotion/recall payload — only possible if an unsupported value (e.g. a channel or func) ends up in the payload map.
Common situations: Effectively none for library users; the payload is fully constructed from string values (emoji text, background ID) so this is a defensive guard.
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 image message: %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/0e30922a8f3aa924.
Report an issue: GitHub.