chenhg5/cc-connect · error
weixin: sendText: empty item_list
Error message
weixin: sendText: empty item_list
What it means
sendText assembles an item_list for the sendMessage API; normally a non-empty text always yields one item. If items is still empty (e.g. text is blank and no other items were added), the request would be invalid, so the client returns this error instead of posting a pointless API call.
Source
Thrown at platform/weixin/client.go:265
return err
}
_, err = c.post(ctx, "ilink/bot/sendtyping", payload, 0, "sendTyping")
return err
}
func (c *apiClient) sendText(ctx context.Context, to, text, contextToken, clientID string) error {
if strings.TrimSpace(contextToken) == "" {
return fmt.Errorf("weixin: context_token is required for send")
}
items := []messageItem{}
if strings.TrimSpace(text) != "" {
items = append(items, messageItem{
Type: messageItemText,
TextItem: &textItem{Text: text},
})
}
if len(items) == 0 {
return fmt.Errorf("weixin: sendText: empty item_list")
}
msg := sendMessageReq{
Msg: weixinOutboundMsg{
FromUserID: "",
ToUserID: to,
ClientID: clientID,
MessageType: messageTypeBot,
MessageState: messageStateFinish,
ItemList: items,
ContextToken: contextToken,
},
}
return c.sendMessage(ctx, &msg)
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Guard at the call site: skip sendText when strings.TrimSpace(text) == ""
- Fix the chunker so empty trailing chunks are not dispatched
- If a no-op is intended, return nil without calling the API
Example fix
// before
if err := c.sendText(ctx, to, chunk, token, id); err != nil { ... }
// after
if strings.TrimSpace(chunk) != "" {
if err := c.sendText(ctx, to, chunk, token, id); err != nil { ... }
} Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(text) == "" { return nil } // nothing to send Type guard
func hasSendableText(t string) bool { return strings.TrimSpace(t) != "" } Try / catch
if err := sendText(ctx, to, text, token, id); err != nil {
if strings.Contains(err.Error(), "empty item_list") { slog.Debug("skipped empty send") ; return nil }
return err
} Prevention
- Filter empty/whitespace chunks before calling sendText
- Fix chunk splitting to never emit zero-length pieces
- Treat this error as a no-op signal rather than a hard failure in streaming flows
When it happens
Trigger: sendText called with whitespace-only or empty text and no additional items — e.g. sendChunks/sendChunk flushing a final empty chunk, or an upstream empty-message edge case.
Common situations: Streaming implementations sending a trailing empty chunk; splitting logic producing zero-length final pieces; callers using sendText as a heartbeat/no-op.
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: context_token is required for send
- weixin: sendMessage: response json: %w: %s
- weixin: sendMessage: ret=%d errcode=%d errmsg=%s
- weixin: getUploadUrl: empty upload_param and upload_full_url
- weixin: %s: empty payload
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/de843d54f114490b.
Report an issue: GitHub.