chenhg5/cc-connect · error
telegram: send file: %w
Error message
telegram: send file: %w
What it means
Wrapped error from the Telegram bot SendDocument call when sending a file attachment to the reply chat (optionally into a topic thread); the Telegram Bot API rejected or failed the document upload.
Source
Thrown at platform/telegram/telegram.go:1178
if !ok {
return fmt.Errorf("telegram: invalid reply context type %T", rctx)
}
bot, err := p.connectedBot("send file")
if err != nil {
return err
}
name := file.FileName
if name == "" {
name = "attachment"
}
params := &tgbot.SendDocumentParams{
ChatID: rc.chatID,
MessageThreadID: rc.threadID,
Document: &models.InputFileUpload{Filename: name, Data: bytes.NewReader(file.Data)},
}
if _, err := bot.SendDocument(ctx, params); err != nil {
return fmt.Errorf("telegram: send file: %w", err)
}
return nil
}
// SendAudio sends synthesized audio back to Telegram.
// It prefers voice messages and falls back to audio files for mp3/m4a on sendVoice failure.
func (p *Platform) SendAudio(ctx context.Context, rctx any, audio []byte, format string) error {
rc, ok := rctx.(replyContext)
if !ok {
return fmt.Errorf("telegram: SendAudio: invalid reply context type %T", rctx)
}
sendData := audio
sendFormat := strings.ToLower(strings.TrimSpace(format))
if sendFormat == "" {
sendFormat = "ogg"
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Check the wrapped cause; if it is a size error, split or compress the file (50 MB bot limit)
- Verify bot membership and chatID/threadID validity
- Retry transient network failures with backoff
- Ensure file.Data is fully read and non-empty before upload
- For very large files, host externally and send a link instead
Example fix
// before
_, err := bot.SendDocument(ctx, params) // 80MB file fails
// after
const maxBotUpload = 50 * 1024 * 1024
if len(file.Data) > maxBotUpload {
return fmt.Errorf("telegram: file too large: %d bytes (max %d)", len(file.Data), maxBotUpload)
}
_, err := bot.SendDocument(ctx, params) Defensive patterns
Strategy: validation
Validate before calling
const maxBotDoc = 50 * 1024 * 1024
if len(file.Data) == 0 { return errors.New("empty file") }
if len(file.Data) > maxBotDoc { return fmt.Errorf("file %d bytes exceeds 50MB bot limit", len(file.Data)) } Try / catch
if err := p.SendFile(ctx, rc, file); err != nil {
var apiErr *tgbot.Error
if errors.As(err, &apiErr) && strings.Contains(apiErr.Description, "too large") {
// split/compress and resend
}
return err
} Prevention
- Enforce the 50MB bot upload limit client-side
- Retry interrupted multipart uploads
- Ensure file buffers are fully loaded before send
- For huge files, share an external link instead
When it happens
Trigger: bot.SendDocument fails: file exceeds Telegram's 50 MB bot upload limit, network interruption during multipart upload, invalid chat/thread, bot blocked, or Telegram API rejection.
Common situations: Sending generated logs/archives larger than 50 MB; unstable connections dropping large uploads; bot removed from the chat; empty or unreadable file.Data buffer.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- discord: send image fallback: %w
- discord: send image: %w
- discord: send file fallback: %w
- discord: send file: %w
- qq: SendFile group: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/98d6302bd8ab911e.
Report an issue: GitHub.