chenhg5/cc-connect · error
attachment exceeds %d bytes
Error message
attachment exceeds %d bytes
What it means
The attachment body downloaded from MAX exceeded maxAttachmentBytes. The reader is capped at maxAttachmentBytes+1 so any payload strictly larger than the limit is detected and rejected before it can exhaust memory.
Source
Thrown at platform/max/max.go:1205
defer cancel()
req, err := http.NewRequestWithContext(dlCtx, http.MethodGet, url, nil)
if err != nil {
return nil, "", err
}
resp, err := p.client.Do(req)
if err != nil {
return nil, "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, "", fmt.Errorf("HTTP %d", resp.StatusCode)
}
data, err := io.ReadAll(io.LimitReader(resp.Body, maxAttachmentBytes+1))
if err != nil {
return nil, "", err
}
if len(data) > maxAttachmentBytes {
return nil, "", fmt.Errorf("attachment exceeds %d bytes", maxAttachmentBytes)
}
return data, resp.Header.Get("Content-Type"), nil
}
// resolveMediaURL asks MAX for the playable/downloadable URL of a video or
// audio attachment. MAX delivers only an opaque token in the message payload
// and exposes /videos/{token} and /audios/{token} for resolution.
func (p *Platform) resolveMediaURL(ctx context.Context, kind, token string) (string, string, error) {
if token == "" {
return "", "", fmt.Errorf("empty token")
}
endpoint := "/videos/"
if kind == "audio" {
endpoint = "/audios/"
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, p.apiBase+endpoint+token, nil)
if err != nil {
return "", "", errView on GitHub (pinned to 4000b2338a)
Solutions
- Increase maxAttachmentBytes if your deployment can afford larger transfers
- Reply to the user that the attachment is too large to relay instead of surfacing a raw error
- Check Content-Length before reading to fail fast
- Compress or link to the original URL instead of downloading the full payload
Example fix
// before
data, ct, err := p.downloadAttachment(ctx, url)
if err != nil { return err }
// after
data, ct, err := p.downloadAttachment(ctx, url)
if err != nil {
if strings.Contains(err.Error(), "attachment exceeds") {
return sendTooLargeNotice(chatID)
}
return err
} Defensive patterns
Strategy: validation
Validate before calling
if att.Size > maxAttachmentBytes { return sendTooLargeNotice(chatID) } Try / catch
if _, _, err := dl(); err != nil && strings.Contains(err.Error(), "attachment exceeds") {
return gracefulTooLargeReply()
} Prevention
- Check Content-Length before downloading when present
- Set maxAttachmentBytes to a value matching your users' typical media sizes
- Reply with a user-friendly size-limit message instead of a raw error
When it happens
Trigger: A user sends an image or file through MAX whose size is larger than maxAttachmentBytes; downloadAttachment reads maxAttachmentBytes+1 bytes and the extra byte triggers this error.
Common situations: Users sharing large videos/high-res photos through the bot bridge; deployment with a conservatively small maxAttachmentBytes configured.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- weixin: %s: response body exceeds %d bytes
- attachment send is disabled by config
- hook input exceeds %d bytes
- codex app-server line exceeds max size (%d bytes): %w
- Content-Length too large: %d
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/986972999b0f2a28.
Report an issue: GitHub.