chenhg5/cc-connect · error
dingtalk: create proactive request: %w
Error message
dingtalk: create proactive request: %w
What it means
This error is returned when http.NewRequestWithContext fails to construct the POST request to the DingTalk proactive-send API. Given a constant API URL and an in-memory body, this failure is rare and typically signals an invalid URL or a nil context/body.
Source
Thrown at platform/dingtalk/dingtalk.go:1685
msgParam, _ := json.Marshal(map[string]string{"title": cardTitleFromContent(content), "text": content})
requestBody = map[string]any{
"robotCode": p.robotCode,
"userIds": []string{rc.senderStaffId},
"msgKey": "sampleMarkdown",
"msgParam": string(msgParam),
}
} else {
return fmt.Errorf("dingtalk: proactive send requires conversationId (group) or senderStaffId (direct)")
}
body, err := json.Marshal(requestBody)
if err != nil {
return fmt.Errorf("dingtalk: marshal proactive message: %w", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("dingtalk: create proactive 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: proactive send request: %w", err)
}
defer func() { _ = resp.Body.Close() }()
respBody, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("dingtalk: proactive send failed: status=%d, body=%s", resp.StatusCode, string(respBody))
}
slog.Debug("dingtalk: proactive message sent", "api", apiURL, "status", resp.StatusCode)
return nil
}View on GitHub (pinned to 4000b2338a)
Solutions
- Check that any configured API base URL for DingTalk is a valid absolute https URL.
- Ensure a non-nil context.Context is passed into the send call.
- Print the wrapped error (%w) to confirm whether it is a URL parse error.
- Verify no custom transport/proxy config produces an invalid request URL.
Example fix
// before
p.Send(nil, rc, msg) // nil context
// after
if err := p.Send(ctx, rc, msg); err != nil {
slog.Error("proactive send failed", "err", err)
} Defensive patterns
Strategy: validation
Validate before calling
if _, err := url.Parse(apiURL); err != nil {
return fmt.Errorf("bad dingtalk api url: %w", err)
}
if ctx == nil {
return errors.New("nil context")
} Try / catch
err := p.Send(ctx, rc, msg)
if err != nil && strings.Contains(err.Error(), "create proactive request") {
slog.Error("request construction failed", "err", err)
} Prevention
- Never pass a nil context; derive from context.Background() or the caller's ctx
- Keep the DingTalk API base URL a constant valid https URL
- Validate any custom endpoint override at config load time
When it happens
Trigger: http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(body)) returns an error — e.g. apiURL failed to parse or ctx is nil.
Common situations: A misconfigured base URL overriding the DingTalk API endpoint; calling the send path with context.Background() forgotten (nil context); proxy/environment manipulation corrupting URL parsing.
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
- create request: %w
- do request: %w
- create AI card: status=%d, body=%s
- stream AI card: status=%d, body=%s
- http get: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/fbe6d51a52681e47.
Report an issue: GitHub.