{"record":{"id":"54e7ad4c4f2f3c58","repo":"chenhg5/cc-connect","slug":"attachment-s-exceeds-size-limit-d-mb","errorCode":null,"errorMessage":"attachment %s exceeds size limit (%d MB)","messagePattern":"attachment (.+?) exceeds size limit \\((.+?) MB\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/send.go","lineNumber":308,"sourceCode":"\tcfg, err := config.Load(resolveConfigPath(\"\"))\n\tif err != nil {\n\t\treturn nil\n\t}\n\treturn cfg\n}\n\n// readAttachment reads a single attachment file, rejecting anything larger than\n// maxSize bytes (resolved by the caller from config/env/default). The limit is\n// enforced before the file is read into memory.\nfunc readAttachment(path string, maxSize int64) ([]byte, string, string, error) {\n\tcleaned := filepath.Clean(path)\n\n\tinfo, err := os.Stat(cleaned)\n\tif err != nil {\n\t\treturn nil, \"\", \"\", fmt.Errorf(\"read attachment %s: %w\", path, err)\n\t}\n\tif info.Size() > maxSize {\n\t\treturn nil, \"\", \"\", fmt.Errorf(\"attachment %s exceeds size limit (%d MB)\", path, maxSize>>20)\n\t}\n\n\tdata, err := os.ReadFile(cleaned)\n\tif err != nil {\n\t\treturn nil, \"\", \"\", fmt.Errorf(\"read attachment %s: %w\", path, err)\n\t}\n\tfileName := filepath.Base(cleaned)\n\treturn data, fileName, detectAttachmentMimeType(fileName, data), nil\n}\n\nfunc detectAttachmentMimeType(fileName string, data []byte) string {\n\text := strings.ToLower(filepath.Ext(fileName))\n\tswitch ext {\n\tcase \".md\", \".markdown\":\n\t\treturn \"text/markdown; charset=utf-8\"\n\t}\n\tif byExt := mime.TypeByExtension(ext); byExt != \"\" {\n\t\treturn byExt","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/send.go#L290-L326","documentation":"readAttachment enforces a maximum attachment size (maxSize in bytes, reported in MB) by stat'ing the file before reading it into memory. Files larger than the limit are rejected with this error, protecting the process from OOM and platforms from oversized uploads.","triggerScenarios":"Running any send command with an attachment whose on-disk size exceeds maxSize (usually the platform's upload limit, e.g. 30 MB), regardless of content type.","commonSituations":"Attaching large videos, raw logs, or database dumps; limit lowered by config for a platform with strict upload caps (e.g. Telegram 50 MB, Feishu smaller).","solutions":["Remove or compress the oversized file (e.g. downscale images, zip logs) and resend","Split the content into multiple smaller attachments","Raise maxSize if your target platform genuinely allows larger uploads"],"exampleFix":"// before\ncc-connect send ./capture-full-4gb.mov\n// after\nffmpeg -i capture-full-4gb.mov -crf 28 capture-small.mp4 && cc-connect send ./capture-small.mp4","handlingStrategy":"validation","validationCode":"path=\"./capture.mov\"; limit=$((30*1024*1024)); size=$(stat -c%s \"$path\"); [ \"$size\" -le \"$limit\" ] || { echo \"too large: $size bytes\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check file sizes before attaching large media","Compress/downscale media proactively","Know your platform's upload cap and size files accordingly"],"tags":["cli","attachments","size-limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}