{"record":{"id":"72ff10f96e5f9385","repo":"Hmbown/CodeWhale","slug":"could-not-parse-configuration-for-route-preference-migration","errorCode":null,"errorMessage":"Could not parse configuration for route preference migration; contents omitted","messagePattern":"Could not parse configuration for route preference migration; contents omitted","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/config_persistence.rs","lineNumber":50,"sourceCode":"\n/// Commit the legacy effective startup selection with its receipt in the same\n/// atomic config write. Settings remains untouched, so an interrupted cleanup\n/// or an older binary cannot erase the user's historical choices. After this\n/// marker, Config never consults those legacy route fields again.\npub(crate) fn migrate_legacy_route_preferences(\n    path: &Path,\n    doc: &mut toml_edit::DocumentMut,\n) -> anyhow::Result<()> {\n    if !crate::config::is_home_config_path(path)\n        || doc\n            .get(\"route_preferences_version\")\n            .and_then(toml_edit::Item::as_integer)\n            .is_some()\n    {\n        return Ok(());\n    }\n    let mut config: crate::config::Config = toml::from_str(&doc.to_string()).map_err(|_| {\n        anyhow::anyhow!(\n            \"Could not parse configuration for route preference migration; contents omitted\"\n        )\n    })?;\n    let previous_config = config.clone();\n    let settings =\n        crate::settings::Settings::load_legacy_route_preferences_read_only().map_err(|_| {\n            anyhow::anyhow!(\n                \"Could not read legacy route preferences; configuration was not changed\"\n            )\n        })?;\n    // An unparsable settings.toml loads as defaults carrying `load_error`, which\n    // keeps the UI usable but is not evidence that no preferences were saved.\n    // This migration is one-way: stamping the version over defaults would retire\n    // the user's real legacy choices unread. Refuse instead, exactly as\n    // `Settings::save_to_path` refuses to overwrite an unreadable document.\n    // Contents stay omitted; the file may hold private text.\n    anyhow::ensure!(\n        settings.load_error.is_none(),","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/config_persistence.rs#L32-L68","documentation":"migrate_legacy_route_preferences, invoked inside mutate_config_document, must deserialize the current TOML document into Config to compute and stamp migrated route preferences. If the document cannot be parsed, it aborts the whole mutation with this error; contents are omitted because the file may hold private text.","triggerScenarios":"Any config write routed through mutate_config_document while the on-disk config document contains invalid TOML or values that fail Config deserialization (wrong types, unknown required fields).","commonSituations":"Corrupted or hand-edited config.toml; schema drift after an upgrade leaving keys with old types; partial writes from a previous crash.","solutions":["Fix the TOML so it deserializes as Config (validate syntax and field types)","Restore a backup of config.toml or regenerate defaults, then retry the operation","Identify offending keys by parsing config.toml with toml::from_str::<Config> in a scratch test and fixing reported fields"],"exampleFix":"# before\nroute_preference = \"auto-pilot\"  # no longer a valid value\n# after\nroute_preference = \"balanced\"","handlingStrategy":"try-catch","validationCode":"// before any mutate_config_document call\nlet raw = std::fs::read_to_string(&config_path)?;\ntoml::from_str::<Config>(&raw)?; // surfaces the real parse error early","typeGuard":null,"tryCatchPattern":"match mutate_config_document(&path, migrator) {\n    Err(e) if e.to_string().contains(\"route preference migration\") => {\n        eprintln!(\"config.toml unparseable; fix or restore before writing\");\n    }\n    other => other?,\n}","preventionTips":["Validate config.toml parses before invoking write paths","Back up config.toml before upgrades","Avoid third-party tools writing unknown keys into config.toml"],"tags":["config","toml","migration","parse-error"],"backgroundTag":"json-parse-error","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}