{"record":{"id":"ac9dec87eab85adb","repo":"Hmbown/CodeWhale","slug":"bundle-at-source-is-bytes-the-limit-is-max-bundle-bytes","errorCode":null,"errorMessage":"bundle at {source} is {} bytes; the limit is {MAX_BUNDLE_BYTES} bytes","messagePattern":"bundle at (.+?) is (.+?) bytes; the limit is (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/config_bundles.rs","lineNumber":102,"sourceCode":"}\n\n/// One bundle section: a flat table of config keys to values. Keys inside a\n/// section are data, not schema, so unknown keys parse here — credential\n/// rejection happens at plan time by name and value shape.\n#[derive(Debug, Clone, Default, Deserialize, Serialize)]\npub struct BundleTable {\n    #[serde(flatten)]\n    pub entries: std::collections::BTreeMap<String, toml::Value>,\n}\n\n// ---------------------------------------------------------------------------\n// Parsing (bounded)\n// ---------------------------------------------------------------------------\n\n/// Parse a bundle from raw bytes, rejecting oversize input before parse.\npub fn parse_bundle_bytes(raw: &[u8], source: &str) -> Result<PortableBundle> {\n    if raw.len() as u64 > MAX_BUNDLE_BYTES {\n        bail!(\n            \"bundle at {source} is {} bytes; the limit is {MAX_BUNDLE_BYTES} bytes\",\n            raw.len()\n        );\n    }\n    let text = std::str::from_utf8(raw)\n        .with_context(|| format!(\"bundle at {source} is not valid UTF-8\"))?;\n    parse_bundle_str(text, source)\n}\n\n/// Parse a bundle document: TOML by default, JSON when the source ends in\n/// `.json` or the document starts with `{`.\npub fn parse_bundle_str(text: &str, source: &str) -> Result<PortableBundle> {\n    let trimmed = text.trim_start();\n    let bundle = if trimmed.starts_with('{') || source.ends_with(\".json\") {\n        // serde_json keeps the last of two identical object keys. A bundle is\n        // a reviewed plan, so a repeated key must fail before anything is\n        // planned or written, exactly as TOML already refuses duplicates.\n        reject_duplicate_json_keys(text)","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/config_bundles.rs#L84-L120","documentation":"parse_bundle_bytes enforces a size bound on configuration bundles before any parsing: raw input larger than MAX_BUNDLE_BYTES is refused with the actual and maximum byte counts. Rejecting oversize input before parse keeps memory bounded and catches obviously-wrong inputs early.","triggerScenarios":"Calling parse_bundle_bytes (public, called by run_import and the oversize-input guard) with raw bytes whose length exceeds MAX_BUNDLE_BYTES — importing a huge file, piping a large stream, or pointing the importer at a binary/log file (crates/cli/src/config_bundles.rs:102).","commonSituations":"Importing the wrong file (e.g. a database dump or tarball instead of the bundle JSON), an exported bundle that accumulated too much history, or piping unbounded stdin into the import command.","solutions":["Check the file size with `wc -c < bundle-file` and confirm it is the intended bundle","Split or prune the bundle contents so it fits under MAX_BUNDLE_BYTES","Re-export a fresh, minimal bundle from the source machine","Ensure you are importing the bundle format (UTF-8 config bundle), not an unrelated file"],"exampleFix":"// before\ncodewhale config-bundles import full-backup.tar.gz   # > MAX_BUNDLE_BYTES\n// after\ncodewhale config-bundles import codewhale-bundle.json","handlingStrategy":"validation","validationCode":"// shell guard before import\nMAX=1048576  # check MAX_BUNDLE_BYTES for the real limit\n[ \"$(wc -c < bundle.json)\" -le \"$MAX\" ] || { echo \"bundle too large\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the file is a config bundle, not a backup/archive, before importing","Check bundle size with `wc -c` before running the import","Prune stale entries before exporting bundles; re-export fresh minimal bundles"],"tags":["cli","config","file-size","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T06:17:15.046Z"}