chenhg5/cc-connect · error
wecom: close multipart writer: %w
Error message
wecom: close multipart writer: %w
What it means
Wrap of multipart.Writer.Close while finalizing the image upload body. Closing a multipart writer over an in-memory buffer only flushes the trailing boundary and effectively cannot fail; this wrap exists to satisfy the error contract and would only fire on internal writer-state corruption.
Source
Thrown at platform/wecom/wecom.go:560
// uploadImageMedia uploads an image to WeChat Work media API and returns the media_id.
func (p *Platform) uploadImageMedia(accessToken string, img core.ImageAttachment) (string, error) {
name := img.FileName
if name == "" {
name = "image.png"
}
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("media", name)
if err != nil {
return "", fmt.Errorf("wecom: create form file: %w", err)
}
if _, err := part.Write(img.Data); err != nil {
return "", fmt.Errorf("wecom: write image data: %w", err)
}
if err := writer.Close(); err != nil {
return "", fmt.Errorf("wecom: close multipart writer: %w", err)
}
apiURL := p.wecomAPIURL("/cgi-bin/media/upload", url.Values{
"access_token": []string{accessToken},
"type": []string{"image"},
})
resp, err := p.apiClient.Post(apiURL, writer.FormDataContentType(), body)
if err != nil {
return "", fmt.Errorf("wecom: upload image: %w", err)
}
defer resp.Body.Close()
var result struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
MediaID string `json:"media_id"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {View on GitHub (pinned to 4000b2338a)
Solutions
- Defensive only — log and skip the image upload if observed
- No user-facing remediation; indicates memory/State corruption if it ever occurs
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at platform/wecom/wecom.go:560 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/f54ff675375990d4.
Report an issue: GitHub.