chenhg5/cc-connect · error

resource too large: total=%d exceeds cap %d

Error message

resource too large: total=%d exceeds cap %d

What it means

Thrown before any chunk loop begins when the server honoured the Range probe (206) and advertised a Content-Range total that exceeds resourceMaxBytes. This is an early-exit guard so the library never starts downloading a file it cannot hold in memory. The advertised total and the cap are both in the message.

Source

Thrown at platform/feishu/resource_download.go:127

	if err != nil {
		// Fallback: try a single plain GET. Some servers reject Range entirely
		// with 4xx instead of silently ignoring it.
		slog.Warn(p.tag()+": first-chunk fetch failed; trying plain GET",
			"error", err, "file_key", fileKey, "type", resType)
		return p.resourceSingleGet(ctx, token, messageID, fileKey, resType)
	}

	// Server ignored our Range header and sent the whole body in one 200.
	if total == 0 {
		if int64(len(first)) > p.resourceMaxBytes {
			return nil, fmt.Errorf("resource too large: body=%d exceeds cap %d", len(first), p.resourceMaxBytes)
		}
		return first, nil
	}

	// Server honoured Range. Loop the remaining chunks.
	if total > p.resourceMaxBytes {
		return nil, fmt.Errorf("resource too large: total=%d exceeds cap %d", total, p.resourceMaxBytes)
	}
	if int64(len(first)) >= total {
		// Defensive: a server that advertises 206 with first slice already
		// covering the whole resource is fine — return what we have.
		return first, nil
	}
	return p.resourceFetchRemainingChunks(ctx, token, messageID, fileKey, resType, total, first)
}

// resourceFetchFirstChunk issues Range bytes=0-0 to learn the total and grab
// the first byte. Returns (first, total, nil) where total==0 means the
// server ignored Range and the entire body is in `first`.
func (p *Platform) resourceFetchFirstChunk(ctx context.Context, token, messageID, fileKey, resType string) ([]byte, int64, error) {
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, p.resourceURL(messageID, fileKey, resType), nil)
	if err != nil {
		return nil, 0, fmt.Errorf("build first-chunk request: %w", err)
	}
	req.Header.Set("Authorization", "Bearer "+token)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Increase resource_max_bytes if the bot has memory headroom for larger files
  2. Reject or short-circuit earlier: check Feishu message metadata for size before calling download
  3. Ask the sender to compress or share a link for oversized files

Example fix

// before (config.toml)
# resource_max_bytes = 33554432
// after
[platform.feishu]
resource_max_bytes = 268435456  # 256 MiB
Defensive patterns

Strategy: validation

Validate before calling

if total, err := probeSize(msgID, key); err == nil && total > maxResourceBytes { skipDownload("declared size too large") }

Type guard

null

Try / catch

if _, err := download(ctx, ...); err != nil && strings.Contains(err.Error(), "total=") {
    slog.Warn("file exceeds cap; rejected pre-download", "err", err)
}

Prevention

When it happens

Trigger: First-chunk probe returns 206 with Content-Range 'bytes 0-0/N' where N > p.resourceMaxBytes; resourceDownloadStream aborts before fetching remaining chunks.

Common situations: A user sends a file larger than the configured cap (e.g. 200 MB file against default cap); or resource_max_bytes was lowered in config and previously-working files now exceed it.

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/78a2320a9662e585. Report an issue: GitHub.