{"record":{"id":"48cc795f73ff74e0","repo":"a-b-street/abstreet","slug":"panel-doesn-t-have","errorCode":null,"errorMessage":"Panel doesn't have {}","messagePattern":"Panel doesn't have (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"widgetry/src/widgets/panel.rs","lineNumber":556,"sourceCode":"pub fn replace(&mut self, ctx: &mut EventCtx, id: &str, mut new: Widget) {\n    if let Some(ref new_id) = new.id {\n        assert_eq!(id, new_id);\n    }\n    new = new.named(id);\n    let old = self\n        .top_level\n        .find_mut(id)\n        .unwrap_or_else(|| panic!(\"Panel doesn't have {}\", id));\n    new.layout.style = old.layout.style;\n    *old = new;\n    self.recompute_layout(ctx, true);\n}","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/widgetry/src/widgets/panel.rs#L538-L574","documentation":"Panel::replace swaps the widget with the given ID for a new one. This fires when top_level.find_mut(id) returns None — the panel contains no widget with that ID, so the caller is trying to replace a widget that was never added or was already removed/taken. It is a UI programming-error guard.","triggerScenarios":"Calling `panel.replace(ctx, \"row3\", new_widget)` where \"row3\" was never added, already removed via take, or its name changed after swap_inner_content.","commonSituations":"Rebuilding panel contents dynamically and replacing a row that a conditional branch skipped; typos in id; replacing after take consumed the original.","solutions":["Check `panel.has_widget(id)` before replace; add the widget instead if missing","Ensure the original widget was named with `.named(id)` so find_mut can locate it","Don't take() a widget you later intend to replace — replace returns the old one if needed via other APIs","Verify content-rebuild logic always inserts the widget being replaced"],"exampleFix":"// before\npanel.replace(ctx, \"row3\", new_row); // panics if absent\n// after\nif panel.has_widget(\"row3\") {\n    panel.replace(ctx, \"row3\", new_row);\n} else {\n    panel.add_widget(new_row.named(\"row3\"));\n}","handlingStrategy":"validation","validationCode":"if panel.has_widget(\"row3\") {\n    panel.replace(ctx, \"row3\", new_row.named(\"row3\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check has_widget before replace; add instead when missing","Ensure widgets are .named(id) at construction","Avoid take() on widgets you will later replace"],"tags":["rust","panel","replace","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}