chenhg5/cc-connect · info

dingtalk: create emotion request: %w

Error message

dingtalk: create emotion request: %w

What it means

This error is returned by sendEmotion when http.NewRequestWithContext fails while building the POST request to the DingTalk emotion endpoint (https://api.dingtalk.com + reply/recall path). Go's NewRequest only errors on an invalid URL or an unparsable method/body, so this indicates the constructed request itself was malformed before any network I/O happened.

Source

Thrown at platform/dingtalk/dingtalk.go:954

		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))
	}
	if len(respBody) == 0 {
		return nil
	}
	var result struct {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Retry the operation; no user-side configuration can cause this
  2. If you modified the source or path constants, restore the original endpoint URL
  3. Report to maintainers with the full error if it reproduces on stock code
Defensive patterns

Strategy: try-catch

Try / catch

if err := p.StartTyping(ctx, rctx); err != nil {
    if strings.Contains(err.Error(), "create emotion request") {
        slog.Error("dingtalk emotion request construction failed (unexpected)", "err", err)
    }
}

Prevention

When it happens

Trigger: http.NewRequestWithContext returns an error in sendEmotion — only possible if the endpoint URL were malformed; since path is a hardcoded constant and the base URL is a literal, this is a defensive guard that is effectively unreachable.

Common situations: None for library users; would only appear if the code's hardcoded path constant became corrupt (e.g. bad local modification).

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/74a012b2af6ba4d1. Report an issue: GitHub.