Hmbown/CodeWhale · error

bundle at is bytes; the limit is bytes

Error message

bundle at {} is {} bytes; the limit is {MAX_BUNDLE_BYTES} bytes

What it means

The CLI's bundle loader checks the size of a bundle file on disk via std::fs::metadata before reading it, and refuses files larger than MAX_BUNDLE_BYTES. This prevents loading arbitrarily large files into memory and parsing untrusted oversized input. The message includes the actual size and the limit for diagnosis.

Solutions

  1. Check the file size (`ls -l` / `wc -c`) and confirm it is the intended bundle.
  2. Trim the bundle below MAX_BUNDLE_BYTES (remove redundant entries) and retry.
  3. If the file is not a bundle, pass the correct path.
  4. If bundles legitimately need to be bigger, this is a product limit to raise — but locally, shrink or split the bundle.

Example fix

// before
codewhale config bundle import ./accumulated-everything.json
// after
ls -l accumulated-everything.json   # exceeds limit?
jq '{providers: .providers[0:3]}' accumulated-everything.json > trimmed.json
codewhale config bundle import ./trimmed.json
Defensive patterns

Strategy: validation

Validate before calling

use std::fs;
let meta = fs::metadata(path)?;
if meta.len() > MAX_BUNDLE_BYTES {
    eprintln!("{} is {} bytes; limit is {}", path.display(), meta.len(), MAX_BUNDLE_BYTES);
    std::process::exit(1);
}

Type guard

fn is_valid_bundle_file(path: &std::path::Path, max: u64) -> bool {
    std::fs::metadata(path).map(|m| m.is_file() && m.len() <= max).unwrap_or(false)
}

Try / catch

match result {
    Err(e) if e.to_string().contains("the limit is") => {
        let size = std::fs::metadata(&path).map(|m| m.len()).unwrap_or(0);
        eprintln!("{path:?} is {size} bytes; trim it below the limit");
    }
    Err(e) => eprintln!("import failed: {e:#}"),
    Ok(_) => {}
}

Prevention

When it happens

Trigger: Invoking a config-bundle command whose source is a local path where `std::fs::metadata(&path).len() > MAX_BUNDLE_BYTES`; the file is never read, the bail fires immediately after the metadata lookup.

Common situations: Pointing the command at the wrong file (a directory dump, a log, a tarball); a bundle that legitimately grew past the limit; stale concatenated exports.

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 Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/f15cf09dcf4be30e. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/config_bundles.rs:1501

    let raw = if args.source == "-" {
        let mut buffer = Vec::new();
        std::io::stdin()
            .lock()
            .take(MAX_BUNDLE_BYTES + 1)
            .read_to_end(&mut buffer)
            .context("reading bundle from stdin")?;
        if buffer.len() as u64 > MAX_BUNDLE_BYTES {
            bail!("stdin bundle exceeds the {MAX_BUNDLE_BYTES} byte limit; refused");
        }
        buffer
    } else if remote_source {
        fetch_bundle(&args.source)?
    } else {
        let path = PathBuf::from(&args.source);
        let metadata = std::fs::metadata(&path)
            .with_context(|| format!("reading bundle at {}", path.display()))?;
        if metadata.len() > MAX_BUNDLE_BYTES {
            bail!(
                "bundle at {} is {} bytes; the limit is {MAX_BUNDLE_BYTES} bytes",
                path.display(),
                metadata.len()
            );
        }
        std::fs::read(&path).with_context(|| format!("reading bundle at {}", path.display()))?
    };

    let bundle = parse_bundle_bytes(&raw, source_label)?;
    let prepared = prepare_import(&bundle, store, scope)?;
    let plan = &prepared.plan;

    println!("import plan ({} scope, {source_label}):", scope.label());
    println!("  added:       {}", plan.added.len());
    println!("  changed:     {}", plan.changed.len());
    println!("  skipped:     {}", plan.skipped.len());
    println!("  conflicting: {}", plan.conflicting.len());
    println!("  rejected:    {}", plan.rejected.len());

View on GitHub (pinned to 433685b202)