chenhg5/cc-connect · error

download exceeds --max-bytes: %d > %d

Error message

download exceeds --max-bytes: %d > %d

What it means

When the HTTP response declares a Content-Length larger than the configured --max-bytes limit, downloadTuiTuiURL aborts before reading the body. Default limit is 25 MiB when maxBytes is unset (<=0). This protects memory by refusing oversized downloads upfront.

Source

Thrown at cmd/cc-connect/tuitui.go:190

func downloadTuiTuiURL(ctx context.Context, rawURL string, maxBytes int64) ([]byte, string, string, error) {
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil)
	if err != nil {
		return nil, "", "", err
	}
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, "", "", err
	}
	defer func() { _ = resp.Body.Close() }()
	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return nil, "", "", fmt.Errorf("HTTP %d", resp.StatusCode)
	}
	limit := maxBytes
	if limit <= 0 {
		limit = 25 << 20
	}
	if resp.ContentLength > limit {
		return nil, "", "", fmt.Errorf("download exceeds --max-bytes: %d > %d", resp.ContentLength, limit)
	}
	data, err := io.ReadAll(io.LimitReader(resp.Body, limit+1))
	if err != nil {
		return nil, "", "", err
	}
	if int64(len(data)) > limit {
		return nil, "", "", fmt.Errorf("download exceeds --max-bytes: %d > %d", len(data), limit)
	}
	mimeType := resp.Header.Get("Content-Type")
	if mimeType == "" || mimeType == "application/octet-stream" {
		mimeType = http.DetectContentType(data)
	}
	return data, mimeType, filenameFromTuiTuiResponse(rawURL, resp.Header.Get("Content-Disposition")), nil
}

func filenameFromTuiTuiResponse(rawURL, contentDisposition string) string {
	if contentDisposition != "" {
		_, params, err := mime.ParseMediaType(contentDisposition)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Raise --max-bytes (e.g. --max-bytes 104857600 for 100MB)
  2. If the file is genuinely unwanted-large, pick a smaller asset URL
  3. Pass 0 or negative only intentionally to fall back to the 25MiB default

Example fix

// before
cc-connect tuitui download --url https://example.com/big.bin
// after
cc-connect tuitui download --url https://example.com/big.bin --max-bytes 104857600
Defensive patterns

Strategy: validation

Validate before calling

resp, err := http.Head(url)
if err == nil && resp.ContentLength > maxBytes {
	return fmt.Errorf("file is %d bytes; raise --max-bytes", resp.ContentLength)
}

Try / catch

if _, _, _, err := downloadTuiTuiURL(ctx, url, maxBytes); err != nil {
	if strings.Contains(err.Error(), "exceeds --max-bytes") {
		// retry with a larger limit or skip
	}
}

Prevention

When it happens

Trigger: resp.ContentLength > limit, i.e. server sends Content-Length header exceeding --max-bytes (or the 25MiB default) in runTuiTuiDownload.

Common situations: Downloading a large binary/attachment while forgetting to raise --max-bytes; default 25MiB limit hit on legitimate big files.

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/ba84fe3b46c9dd39. Report an issue: GitHub.