chenhg5/cc-connect · error
marshal request: %w
Error message
marshal request: %w
What it means
getDownloadURL wraps a json.Marshal failure of the request body {downloadCode, robotCode}. With a plain map[string]string this is nearly impossible at runtime (map[string]string always marshals), so encountering it indicates an unexpected marshalling defect; it exists to preserve the error chain.
Source
Thrown at platform/dingtalk/dingtalk.go:686
mimeType = "audio/amr" // Default to AMR if not specified
}
return data, mimeType, nil
}
func (p *Platform) getDownloadURL(downloadCode string) (string, error) {
token, err := p.getAccessToken()
if err != nil {
return "", fmt.Errorf("get access token: %w", err)
}
reqBody := map[string]string{
"downloadCode": downloadCode,
"robotCode": p.robotCode,
}
bodyBytes, err := json.Marshal(reqBody)
if err != nil {
return "", fmt.Errorf("marshal request: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPost,
"https://api.dingtalk.com/v1.0/robot/messageFiles/download",
bytes.NewReader(bodyBytes))
if err != nil {
return "", fmt.Errorf("create 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("do request: %w", err)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Confirm you are running an unmodified build of the platform package.
- If reproducible, report a bug with the full wrapped error chain; the request body is a fixed map[string]string and cannot normally fail.
- No user-side configuration change can prevent this; treat as an internal invariant violation.
Defensive patterns
Strategy: try-catch
Try / catch
if err != nil && strings.Contains(err.Error(), "marshal request") {
// Should be unreachable; treat as a bug
log.Error("dingtalk: internal marshal failure", "err", err)
return fmt.Errorf("internal error, please report: %w", err)
} Prevention
- Keep the request body a marshalable type (map[string]string or a struct of strings)
- Never inject unmarshalable values (channels, funcs) into request maps
- Report occurrences upstream as internal invariant violations
When it happens
Trigger: json.Marshal(reqBody) returned an error in getDownloadURL before issuing the HTTP request.
Common situations: In practice: should never occur with the current request shape. If seen, it points to a modified/broken build or an unexpected runtime fault rather than user configuration.
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
- decode response: %w
- dingtalk: marshal emotion request: %w
- dingtalk: marshal image message: %w
- dingtalk: marshal file message: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/134ee1157c02f638.
Report an issue: GitHub.