{"record":{"id":"98d6302bd8ab911e","repo":"chenhg5/cc-connect","slug":"telegram-send-file-w","errorCode":null,"errorMessage":"telegram: send file: %w","messagePattern":"telegram: send file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1178,"sourceCode":"\tif !ok {\n\t\treturn fmt.Errorf(\"telegram: invalid reply context type %T\", rctx)\n\t}\n\tbot, err := p.connectedBot(\"send file\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tname := file.FileName\n\tif name == \"\" {\n\t\tname = \"attachment\"\n\t}\n\tparams := &tgbot.SendDocumentParams{\n\t\tChatID:          rc.chatID,\n\t\tMessageThreadID: rc.threadID,\n\t\tDocument:        &models.InputFileUpload{Filename: name, Data: bytes.NewReader(file.Data)},\n\t}\n\tif _, err := bot.SendDocument(ctx, params); err != nil {\n\t\treturn fmt.Errorf(\"telegram: send file: %w\", err)\n\t}\n\treturn nil\n}\n\n// SendAudio sends synthesized audio back to Telegram.\n// It prefers voice messages and falls back to audio files for mp3/m4a on sendVoice failure.\nfunc (p *Platform) SendAudio(ctx context.Context, rctx any, audio []byte, format string) error {\n\trc, ok := rctx.(replyContext)\n\tif !ok {\n\t\treturn fmt.Errorf(\"telegram: SendAudio: invalid reply context type %T\", rctx)\n\t}\n\n\tsendData := audio\n\tsendFormat := strings.ToLower(strings.TrimSpace(format))\n\tif sendFormat == \"\" {\n\t\tsendFormat = \"ogg\"\n\t}\n","sourceCodeStart":1160,"sourceCodeEnd":1196,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1160-L1196","documentation":"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.","triggerScenarios":"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.","commonSituations":"Sending generated logs/archives larger than 50 MB; unstable connections dropping large uploads; bot removed from the chat; empty or unreadable file.Data buffer.","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"],"exampleFix":"// before\n_, err := bot.SendDocument(ctx, params) // 80MB file fails\n// after\nconst maxBotUpload = 50 * 1024 * 1024\nif len(file.Data) > maxBotUpload {\n    return fmt.Errorf(\"telegram: file too large: %d bytes (max %d)\", len(file.Data), maxBotUpload)\n}\n_, err := bot.SendDocument(ctx, params)","handlingStrategy":"validation","validationCode":"const maxBotDoc = 50 * 1024 * 1024\nif len(file.Data) == 0 { return errors.New(\"empty file\") }\nif len(file.Data) > maxBotDoc { return fmt.Errorf(\"file %d bytes exceeds 50MB bot limit\", len(file.Data)) }","typeGuard":null,"tryCatchPattern":"if err := p.SendFile(ctx, rc, file); err != nil {\n    var apiErr *tgbot.Error\n    if errors.As(err, &apiErr) && strings.Contains(apiErr.Description, \"too large\") {\n        // split/compress and resend\n    }\n    return err\n}","preventionTips":["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"],"tags":["telegram","file-upload","api-error"],"backgroundTag":"api-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}