{"record":{"id":"afa9848cc0be914c","repo":"Hmbown/CodeWhale","slug":"segment-exists-or-was-inserted-above","errorCode":null,"errorMessage":"segment exists or was inserted above","messagePattern":"segment exists or was inserted above","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/config_document.rs","lineNumber":433,"sourceCode":"    root: &'a mut toml_edit::Table,\n    segments: &[&str],\n    lookup: PathLookup,\n) -> Result<Option<&'a mut dyn toml_edit::TableLike>> {\n    let mut current: &mut dyn toml_edit::TableLike = root;\n    for segment in segments {\n        if current.get(segment).is_none() {\n            match lookup {\n                PathLookup::Create => {\n                    let mut table = toml_edit::Table::new();\n                    table.set_implicit(true);\n                    current.insert(segment, toml_edit::Item::Table(table));\n                }\n                PathLookup::Existing => return Ok(None),\n            }\n        }\n        let item = current\n            .get_mut(segment)\n            .expect(\"segment exists or was inserted above\");\n        match item.as_table_like_mut() {\n            Some(table) => current = table,\n            None => match lookup {\n                PathLookup::Create => bail!(\"`{segment}` in config.toml must be a table\"),\n                PathLookup::Existing => return Ok(None),\n            },\n        }\n    }\n    Ok(Some(current))\n}\n\n#[cfg(test)]\nmod tests {\n    #[test]\n    fn healing_lifts_nested_extras_towers_to_the_top_level() {\n        let tmp = tempfile::tempdir().expect(\"tempdir\");\n        let path = tmp.path().join(\"config.toml\");\n        std::fs::write(","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/config/src/config_document.rs#L415-L451","documentation":"Invariant inside table_like_at_path_mut(): when descending a segment it either finds an existing table-like item or just inserted one; unwrap of the newly inserted entry can only fail if insertion silently failed, which indicates a toml_edit API misuse or code bug rather than user error.","triggerScenarios":"Thrown at crates/config/src/config_document.rs:433 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect how the segment was inserted/mutated and fix the insertion path","Report a bug with the config path segments that triggered it"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}