chenhg5/cc-connect · error

weixin: %s: empty payload

Error message

weixin: %s: empty payload

What it means

uploadToWeixinCDN refuses to upload a zero-length payload, returning an error labeled with the sending operation (SendImage/SendFile/SendAudio). Uploading empty bytes to the WeChat CDN would produce a corrupt/invalid media item.

Source

Thrown at platform/weixin/media_outbound.go:57

}

func (p *Platform) resolveReplyContext(replyCtx any) (*replyContext, error) {
	rc, ok := replyCtx.(*replyContext)
	if !ok || rc == nil {
		return nil, fmt.Errorf("weixin: invalid reply context")
	}
	if strings.TrimSpace(rc.contextToken) == "" {
		rc.contextToken = p.getContextToken(rc.peerUserID)
	}
	if strings.TrimSpace(rc.contextToken) == "" {
		return nil, fmt.Errorf("weixin: missing context_token for peer %q", rc.peerUserID)
	}
	return rc, nil
}

func (p *Platform) uploadToWeixinCDN(ctx context.Context, to string, plaintext []byte, mediaType int, label string) (*cdnUploadedRef, error) {
	if len(plaintext) == 0 {
		return nil, fmt.Errorf("weixin: %s: empty payload", label)
	}
	if strings.TrimSpace(p.cdnBaseURL) == "" {
		return nil, fmt.Errorf("weixin: cdn_base_url is empty")
	}
	rawSize := len(plaintext)
	aesKey := make([]byte, 16)
	if _, err := rand.Read(aesKey); err != nil {
		return nil, fmt.Errorf("weixin: %s: aes key: %w", label, err)
	}
	filekey := randomHex(16)
	req := getUploadURLRequest{
		Filekey:     filekey,
		MediaType:   mediaType,
		ToUserID:    to,
		Rawsize:     rawSize,
		Rawfilemd5:  md5Hex(plaintext),
		Filesize:    aesECBPaddedSize(rawSize),
		NoNeedThumb: true,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Verify the attachment data is fully downloaded and non-empty before calling Send*.
  2. Check the file on disk has size > 0 (os.Stat) before reading it into memory.
  3. Log/handle upstream fetch errors so a failed download is not passed through as empty bytes.

Example fix

// before
if err := fetchAttachment(); err != nil { /* ignored */ }
p.SendImage(ctx, rc, core.ImageAttachment{Data: data}) // weixin: SendImage: empty payload
// after
if len(data) == 0 { return errors.New("attachment download failed") }
p.SendImage(ctx, rc, core.ImageAttachment{Data: data})
Defensive patterns

Strategy: validation

Validate before calling

if len(payload) == 0 { return errors.New("refusing to send empty media payload") }

Try / catch

if err := p.SendFile(ctx, rc, f); err != nil && strings.Contains(err.Error(), "empty payload") { log.Error("media bytes were empty; check upstream download") }

Prevention

When it happens

Trigger: SendImage with img.Data == nil/empty, SendFile with file.Data empty, or SendAudio where the audio bytes (after any conversion) end up empty.

Common situations: Attachment download from the messaging platform returned 0 bytes (failed fetch silently ignored); reading a file that was truncated or a directory; caller passed nil data by mistake.

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/2303012a10a5e481. Report an issue: GitHub.