{"record":{"id":"0e30922a8f3aa924","repo":"chenhg5/cc-connect","slug":"dingtalk-marshal-emotion-request-w","errorCode":null,"errorMessage":"dingtalk: marshal emotion request: %w","messagePattern":"dingtalk: marshal emotion request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"platform/dingtalk/dingtalk.go","lineNumber":949,"sourceCode":"\tif recall {\n\t\tpath = \"/v1.0/robot/emotion/recall\"\n\t}\n\trequestBody := dingtalkEmotionRequest{\n\t\tRobotCode:          p.robotCode,\n\t\tOpenMsgID:          rc.messageID,\n\t\tOpenConversationID: rc.conversationId,\n\t\tEmotionType:        2,\n\t\tEmotionName:        emoji,\n\t\tTextEmotion: dingtalkTextEmotion{\n\t\t\tEmotionID:    customTextEmotionID,\n\t\t\tEmotionName:  emoji,\n\t\t\tText:         emoji,\n\t\t\tBackgroundID: customTextEmotionBackground,\n\t\t},\n\t}\n\tbody, err := json.Marshal(requestBody)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: marshal emotion request: %w\", err)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, \"https://api.dingtalk.com\"+path, bytes.NewReader(body))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dingtalk: create emotion 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: emotion request: %w\", err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\trespBody, _ := io.ReadAll(resp.Body)\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"dingtalk: emotion returned status %d: %s\", resp.StatusCode, string(respBody))","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/dingtalk/dingtalk.go#L931-L967","documentation":"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.","triggerScenarios":"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.","commonSituations":"Effectively none for library users; the payload is fully constructed from string values (emoji text, background ID) so this is a defensive guard.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := p.AddDoneReaction(ctx, msg); err != nil {\n    if strings.Contains(err.Error(), \"marshal emotion request\") {\n        // unreachable in practice; log and continue\n        slog.Warn(\"dingtalk emotion marshal (unexpected)\", \"err\", err)\n    }\n}","preventionTips":["Only construct emotion payloads via the library's own sendEmotion path","Avoid local modifications that insert dynamic values into the request map"],"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-14T00:17:10.932Z"}