{"record":{"id":"9c81304dbdcaff05","repo":"Hmbown/CodeWhale","slug":"serialized-typed-config-was-not-valid-toml","errorCode":null,"errorMessage":"serialized typed config was not valid TOML","messagePattern":"serialized typed config was not valid TOML","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/config_bundles.rs","lineNumber":966,"sourceCode":"    if key.starts_with(\"skills\") || key.starts_with(\"tools\") || key.starts_with(\"snapshots\") {\n        return ExportSection::Preferences;\n    }\n    if key.starts_with(\"auth.\") {\n        return ExportSection::Drop;\n    }\n    match scope {\n        BundleScope::Global => ExportSection::Global,\n        BundleScope::Project => ExportSection::Project,\n    }\n}\n\nfn config_document(config: &ConfigToml) -> Result<toml::map::Map<String, toml::Value>> {\n    // Serialize through TOML text before parsing to Value. Direct\n    // `Value::try_from` double-encodes datetime values held inside flattened\n    // `toml::Value` extras as the serializer's private marker table.\n    let text = toml::to_string(config).context(\"serializing typed config for bundle\")?;\n    let value: toml::Value =\n        toml::from_str(&text).map_err(|_| anyhow!(\"serialized typed config was not valid TOML\"))?;\n    let toml::Value::Table(mut table) = value else {\n        bail!(\"typed config did not serialize to a TOML table\");\n    };\n    // `selected_provider_id` is runtime parse state and is skipped by serde;\n    // restore the exact named-provider identity that ConfigStore writes.\n    table.insert(\n        \"provider\".to_string(),\n        toml::Value::String(config.provider_id().to_string()),\n    );\n    Ok(table)\n}\n\n/// Return a recursively scrubbed export value. Secret-bearing leaves and\n/// machine-local paths are omitted rather than replaced with a placeholder,\n/// because a placeholder would become literal config on re-import.\nfn sanitize_export_value(path: &str, value: &toml::Value) -> Option<toml::Value> {\n    sanitize_export_value_at(path, value, 0)\n}","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/config_bundles.rs#L948-L984","documentation":"config_document round-trips the typed ConfigToml through TOML text (to avoid double-encoding datetime values via Value::try_from) and then parses it back to a toml::Value. If that reparse fails, the serializer produced text that is not valid TOML — an internal invariant violation, since toml::to_string output should always reparse. The error deliberately carries no config contents.","triggerScenarios":"toml::from_str on the output of toml::to_string(config) fails inside config_document, which is invoked by export_bundle, prepare_import, and config value inspection helpers.","commonSituations":"A ConfigToml containing exotic flattened toml::Value extras or unusual value types that the serializer renders in a form the parser rejects — practically a bug in the interaction between the typed config and the toml crate version in use.","solutions":["Simplify the config: remove unusual/unknown keys or exotic value types from the config file and retry.","Check for a toml crate version mismatch or known round-trip bug; update the dependency.","Report the offending config shape as a bug — this path should never fail for valid typed config.","Validate the config file parses as TOML on its own before exporting/importing."],"exampleFix":"// before (config.toml)\n[weird]\nkey = 1979-05-27T07:32:00Z-extra\n// after (config.toml)\n[weird]\nkey = 1979-05-27T07:32:00Z","handlingStrategy":"try-catch","validationCode":"let raw = std::fs::read_to_string(config_path)?; let _probe: toml::Value = toml::from_str(&raw).expect(\"base config must be valid TOML\");","typeGuard":null,"tryCatchPattern":"match export_bundle(...) { Err(e) if e.to_string().contains(\"was not valid TOML\") => eprintln!(\"internal round-trip bug; simplify config and report\"), other => other, }","preventionTips":["Keep the config file free of unknown/exotic keys.","Keep the toml crate at a consistent version.","Validate config.toml parses before export/import operations.","Report reproducible shapes as bugs — this is an invariant path."],"tags":["toml","serialization","config"],"backgroundTag":"toml-parse-error","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}