chenhg5/cc-connect · error
weixin: empty image
Error message
weixin: empty image
What it means
Validation guard in Weixin SendImage: the image attachment's Data slice has zero length, so there are no bytes to upload to the WeChat CDN; the caller produced an empty image attachment.
Source
Thrown at platform/weixin/media_outbound.go:170
func buildVideoMessageItem(ref *cdnUploadedRef) messageItem {
return messageItem{
Type: messageItemVideo,
VideoItem: &videoItem{
Media: mediaFromUploadRef(ref),
VideoSize: ref.cipherSize,
},
}
}
// SendImage implements core.ImageSender.
func (p *Platform) SendImage(ctx context.Context, replyCtx any, img core.ImageAttachment) error {
rc, err := p.resolveReplyContext(replyCtx)
if err != nil {
return err
}
if len(img.Data) == 0 {
return fmt.Errorf("weixin: empty image")
}
ref, err := p.uploadToWeixinCDN(ctx, rc.peerUserID, img.Data, uploadMediaImage, "SendImage")
if err != nil {
return err
}
item := messageItem{
Type: messageItemImage,
ImageItem: &imageItem{
Media: &cdnMedia{
EncryptQueryParam: ref.downloadParam,
AESKey: formatAesKeyForAPI(ref.aesKey),
EncryptType: 1,
},
MidSize: ref.cipherSize,
},
}
return p.sendSingleItem(ctx, rc, item)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Ensure the image bytes are populated (len(img.Data) > 0) before calling SendImage.
- Fix the upstream generation/download step that produced empty image data.
- Guard at the call site: skip or error out early when image data is empty.
Example fix
// before
data, _ := renderScreenshot() // error ignored, data empty
p.SendImage(ctx, rc, core.ImageAttachment{Data: data}) // weixin: empty image
// after
data, err := renderScreenshot()
if err != nil || len(data) == 0 { return fmt.Errorf("screenshot: %w", err) } Defensive patterns
Strategy: validation
Validate before calling
if len(img.Data) == 0 { return errors.New("image attachment is empty; skipping send") } Try / catch
if err := p.SendImage(ctx, rc, img); err != nil && strings.Contains(err.Error(), "empty image") { log.Error("empty image produced by upstream render step") } Prevention
- Check image byte length before every SendImage call
- Surface render/screenshot errors instead of dropping them
- Unit-test the attachment pipeline with real bytes
When it happens
Trigger: Calling SendImage with core.ImageAttachment{Data: nil} or Data: []byte{}.
Common situations: Agent produced an image attachment whose bytes failed to load (screenshot tool returned nothing); upstream decode path swallowed an error and returned empty data.
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
- weixin: empty file
- weixin: empty audio
- invalid remote image URL
- unsupported remote image MIME %q
- weixin: getUploadUrl: empty upload_param and upload_full_url
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/6ef28ce78016ac20.
Report an issue: GitHub.