Hmbown/CodeWhale · error
segment exists or was inserted above
Error message
segment exists or was inserted above
What it means
While walking the config document, table_like_at_path_mut calls current.get_mut(segment) and expects the segment to be present, because earlier iterations either found it or inserted it (for PathLookup::Create). If traversal somehow reaches a missing segment, this expect fires — a structural invariant of the walk.
Solutions
- Inspect the Create/Existing handling just above: every segment must exist or be inserted before this line.
- Fix the insertion branch so Create inserts missing intermediate tables.
- Check for unsynchronized concurrent access to the same toml document.
Defensive patterns
Strategy: try-catch
Try / catch
// internal invariant; surface as bug, not user error std::panic::catch_unwind(|| doc.unset(&path))
Prevention
- Test unset/set traversal over segments that do and do not exist.
- Never mutate the toml document outside the documented lock discipline.
- Preserve the insert-before-walk ordering when refactoring.
When it happens
Trigger: table_like_at_path_mut (used by set_config_document_value and unset_config_document_value) reaching a get_mut(segment) that is None — possible only if the insert branch above it was skipped or a prior mutation removed the segment mid-walk.
Common situations: A regression in the insert logic for PathLookup::Create, or concurrent document mutation violating the lock discipline (the shared-lock test guards this). Not triggerable from config file contents.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Create lookups always yield a table
- provider authority checked above
- a CNB access token is not configured in the Codewhale…
- account_agent_model_unconfigured
- active plugin registry is missing its pre-dotenv…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/afa9848cc0be914c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/config/src/config_document.rs:445
root: &'a mut toml_edit::Table,
segments: &[&str],
lookup: PathLookup,
) -> Result<Option<&'a mut dyn toml_edit::TableLike>> {
let mut current: &mut dyn toml_edit::TableLike = root;
for segment in segments {
if current.get(segment).is_none() {
match lookup {
PathLookup::Create => {
let mut table = toml_edit::Table::new();
table.set_implicit(true);
current.insert(segment, toml_edit::Item::Table(table));
}
PathLookup::Existing => return Ok(None),
}
}
let item = current
.get_mut(segment)
.expect("segment exists or was inserted above");
match item.as_table_like_mut() {
Some(table) => current = table,
None => match lookup {
PathLookup::Create => bail!("`{segment}` in config.toml must be a table"),
PathLookup::Existing => return Ok(None),
},
}
}
Ok(Some(current))
}
#[cfg(test)]
mod tests {
#[test]
fn healing_keeps_a_non_table_extras_key_it_cannot_lift() {
// `extras` is where the config structs flatten unknown keys, so a
// scalar or array under that exact name round-trips through the typed
// path as ordinary user data. Healing used to `remove()` it beforeView on GitHub (pinned to 73e0f67d83)