{"record":{"id":"e22143243d60cf1e","repo":"chenhg5/cc-connect","slug":"resource-too-large-body-d-exceeds-cap-d","errorCode":null,"errorMessage":"resource too large: body=%d exceeds cap %d","messagePattern":"resource too large: body=(.+?) exceeds cap (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/feishu/resource_download.go","lineNumber":120,"sourceCode":"// resourceDownloadStream executes the actual download. Split out so the\n// helper's preflight (validation, token, defaults) stays readable.\nfunc (p *Platform) resourceDownloadStream(ctx context.Context, token, messageID, fileKey, resType string) ([]byte, error) {\n\tprobeCtx, cancel := context.WithTimeout(ctx, resourceRangeProbeTimeout)\n\tdefer cancel()\n\n\tfirst, total, err := p.resourceFetchFirstChunk(probeCtx, token, messageID, fileKey, resType)\n\tif err != nil {\n\t\t// Fallback: try a single plain GET. Some servers reject Range entirely\n\t\t// with 4xx instead of silently ignoring it.\n\t\tslog.Warn(p.tag()+\": first-chunk fetch failed; trying plain GET\",\n\t\t\t\"error\", err, \"file_key\", fileKey, \"type\", resType)\n\t\treturn p.resourceSingleGet(ctx, token, messageID, fileKey, resType)\n\t}\n\n\t// Server ignored our Range header and sent the whole body in one 200.\n\tif total == 0 {\n\t\tif int64(len(first)) > p.resourceMaxBytes {\n\t\t\treturn nil, fmt.Errorf(\"resource too large: body=%d exceeds cap %d\", len(first), p.resourceMaxBytes)\n\t\t}\n\t\treturn first, nil\n\t}\n\n\t// Server honoured Range. Loop the remaining chunks.\n\tif total > p.resourceMaxBytes {\n\t\treturn nil, fmt.Errorf(\"resource too large: total=%d exceeds cap %d\", total, p.resourceMaxBytes)\n\t}\n\tif int64(len(first)) >= total {\n\t\t// Defensive: a server that advertises 206 with first slice already\n\t\t// covering the whole resource is fine — return what we have.\n\t\treturn first, nil\n\t}\n\treturn p.resourceFetchRemainingChunks(ctx, token, messageID, fileKey, resType, total, first)\n}\n\n// resourceFetchFirstChunk issues Range bytes=0-0 to learn the total and grab\n// the first byte. Returns (first, total, nil) where total==0 means the","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/resource_download.go#L102-L138","documentation":"Thrown when the Feishu server ignored the Range header and returned the entire resource in one 200 response, and that body is larger than resourceMaxBytes (the in-memory download cap). The library buffers downloads in memory and enforces this cap to prevent OOM from oversized files. The error reports the actual body size and the configured cap.","triggerScenarios":"resourceFetchFirstChunk received HTTP 200 (total==0, whole body delivered) for a resource whose downloaded size exceeds p.resourceMaxBytes, e.g. a user sends a very large file to the bot.","commonSituations":"Users sending 100+ MB files through Feishu chat while resource_max_bytes is at its default; or a proxy/CDN stripping the Range header so large files always arrive as one full 200 body.","solutions":["Raise resource_max_bytes in config.toml if the file size is acceptable for memory","Tell the sender the file exceeds the bot's size cap; deliver via a link instead of download","Investigate intermediaries (proxy) that strip the Range header, forcing whole-body responses"],"exampleFix":"// before (config.toml)\n# resource_max_bytes not set  -> default cap\n// after\n[platform.feishu]\nresource_max_bytes = 104857600  # 100 MiB","handlingStrategy":"validation","validationCode":"if fileSizeKnown && fileSize > maxResourceBytes { skipDownload(\"file too large\") }","typeGuard":"null","tryCatchPattern":"data, err := downloadResourceChunked(ctx, msgID, key, \"file\")\nif err != nil && strings.HasPrefix(err.Error(), \"resource too large\") {\n    reply(\"Sorry, that file exceeds the bot's download limit.\")\n    return\n}","preventionTips":["Set resource_max_bytes explicitly in config.toml to a value matching expected user uploads","Announce the bot's file-size limit to users","Prefer linking to Feishu-hosted files over downloading huge ones","Watch logs for repeated 'resource too large' to right-size the cap"],"tags":["go","feishu","file-size","memory"],"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"}