chenhg5/cc-connect · error
wecom-ws: image data is empty
Error message
wecom-ws: image data is empty
What it means
SendImage rejects the call when core.ImageAttachment.Data is empty (len == 0) because there are no image bytes to chunk-upload to WeCom. This is a fail-fast validation before the chunked media upload, which would otherwise fail with a less obvious 'empty media data' error inside uploadWSMedia.
Source
Thrown at platform/wecom/websocket_outbound_media.go:31
"github.com/chenhg5/cc-connect/core"
)
const (
wecomWSUploadChunkSize = 512 * 1024
wecomWSUploadMaxChunks = 100
)
// SendImage uploads and sends an image through the WeCom AI Bot WebSocket API.
func (p *WSPlatform) SendImage(ctx context.Context, rctx any, img core.ImageAttachment) error {
rc, ok := rctx.(wsReplyContext)
if !ok {
return fmt.Errorf("wecom-ws: SendImage: invalid reply context type %T", rctx)
}
if rc.chatID == "" {
return fmt.Errorf("wecom-ws: chatID is empty, cannot send image")
}
if len(img.Data) == 0 {
return fmt.Errorf("wecom-ws: image data is empty")
}
mediaID, err := p.uploadWSMedia(ctx, "image", wsImageFileName(img), img.Data)
if err != nil {
return fmt.Errorf("wecom-ws: send image: %w", err)
}
if err := p.sendWSMediaMessage(ctx, rc.chatID, "image", mediaID); err != nil {
return fmt.Errorf("wecom-ws: send image: %w", err)
}
return nil
}
func (p *WSPlatform) uploadWSMedia(ctx context.Context, mediaType, filename string, data []byte) (string, error) {
totalChunks := (len(data) + wecomWSUploadChunkSize - 1) / wecomWSUploadChunkSize
if totalChunks == 0 {
return "", fmt.Errorf("empty media data")
}
if totalChunks > wecomWSUploadMaxChunks {View on GitHub (pinned to 4000b2338a)
Solutions
- Verify img.Data is populated before calling SendImage: check the file read succeeded and len(img.Data) > 0.
- Fix the upstream producer of the ImageAttachment (agent adapter or file loader) so it embeds actual bytes or returns an error.
- Check that the source file on disk is non-empty and was read completely (no early EOF handling that returns nil data).
- In tests, set Data to a small valid image payload (e.g. []byte of PNG bytes).
Example fix
// before
data, _ := os.ReadFile(path) // error ignored
core.ImageAttachment{FileName: "x.png"} // Data never set
// after
data, err := os.ReadFile(path)
if err != nil { return err }
core.ImageAttachment{FileName: "x.png", Data: data} Defensive patterns
Strategy: validation
Validate before calling
if len(img.Data) == 0 {
return errors.New("cannot send image: attachment has no data")
} Try / catch
if err := platform.SendImage(ctx, rctx, img); err != nil {
if strings.Contains(err.Error(), "image data is empty") {
// log and skip; investigate the attachment producer
}
} Prevention
- Always check the error from file reads before building an ImageAttachment.
- Validate attachments at the boundary: reject empty Data early in your pipeline.
- Ensure agent adapters emit inline bytes, not just metadata, for image attachments.
- Add a test fixture asserting Data is non-empty for every image send path.
When it happens
Trigger: Calling SendImage with an ImageAttachment whose Data slice is nil or zero-length: constructing the attachment without loading file contents, a failed/cancelled file read that returned no bytes but no error, or forwarding an attachment where only metadata (filename/mime) was set.
Common situations: os.ReadFile failing silently in caller code that ignores the error and passes a nil Data; agent adapters emitting attachment metadata without inline data; test fixtures that forgot to fill Data; files of zero bytes on disk.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- wecom-ws: chatID is empty, cannot send image
- wecom-ws: send image: %w
- empty path
- wecom-ws: SendImage: invalid reply context type %T
- empty media data
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/d78ea029a659de09.
Report an issue: GitHub.