chenhg5/cc-connect · error
wecom-ws: send file: %w
Error message
wecom-ws: send file: %w
What it means
SendFile wraps any failure from uploadWSMedia (the init/chunk/finish WebSocket upload that yields a media_id) with this prefix. The wrapped error chain contains the real cause — upload chunk timeout, finish failure, or decode error from the same file.
Source
Thrown at platform/wecom/websocket_outbound_media.go:173
}
}
// SendFile uploads and sends a file through the WeCom AI Bot WebSocket API.
func (p *WSPlatform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {
rc, ok := rctx.(wsReplyContext)
if !ok {
return fmt.Errorf("wecom-ws: SendFile: invalid reply context type %T", rctx)
}
if rc.chatID == "" {
return fmt.Errorf("wecom-ws: chatID is empty, cannot send file")
}
if len(file.Data) == 0 {
return fmt.Errorf("wecom-ws: file data is empty")
}
mediaID, err := p.uploadWSMedia(ctx, "file", wsFileFileName(file), file.Data)
if err != nil {
return fmt.Errorf("wecom-ws: send file: %w", err)
}
if err := p.sendWSMediaMessage(ctx, rc.chatID, "file", mediaID); err != nil {
return fmt.Errorf("wecom-ws: send file: %w", err)
}
return nil
}
func wsFileFileName(file core.FileAttachment) string {
name := filepath.Base(strings.TrimSpace(file.FileName))
if name != "" && name != "." {
return name
}
switch strings.ToLower(file.MimeType) {
case "text/html":
return "file.html"
case "application/pdf":
return "file.pdf"
case "text/plain":View on GitHub (pinned to 4000b2338a)
Solutions
- Unwrap the error chain (%w) to find the underlying upload stage that failed
- Retry SendFile once after verifying the WS connection; transient timeouts are common
- Reduce file size or chunk size if timeouts recur
- Check WeCom AI Bot quota/permissions for media uploads
Defensive patterns
Strategy: try-catch
Validate before calling
if len(file.Data) == 0 || file.Data == nil {
return fmt.Errorf("no data to upload")
} Try / catch
if err := p.SendFile(ctx, rc, file); err != nil {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
// reconnect WS and retry upload once
}
return fmt.Errorf("file delivery failed: %w", err)
} Prevention
- Always inspect errors.As/Unwrap — the real cause is one level down
- Check WS health before large uploads
- Retry once for transient timeouts; abort on repeated failures
When it happens
Trigger: SendFile → uploadWSMedia returns any error: chunk send timeout, finish timeout, finish decode failure, or empty media_id.
Common situations: WS connection dropped during a large upload; per-chunk ack timeout on slow networks; WeCom server rejecting the upload session due to size or permissions.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- upload chunk %d: %w
- upload finish: %w
- upload finish: empty media_id
- wecom-ws: ack timeout
- synthesize: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/6baa24db8e69f586.
Report an issue: GitHub.