{"record":{"id":"f83739370ef3e872","repo":"LGUG2Z/komorebi","slug":"there-is-no-window-in-this-container-at-index-idx","errorCode":null,"errorMessage":"there is no window in this container at index {idx}","messagePattern":"there is no window in this container at index (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"komorebi/src/window_manager.rs","lineNumber":2761,"sourceCode":"\n        tracing::info!(\"focusing container window at index {idx}\");\n\n        let container =\n            if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {\n                container\n            } else {\n                self.focused_container_mut()?\n            };\n\n        let len = NonZeroUsize::new(container.windows().len())\n            .ok_or_eyre(\"there must be at least one window in a container\")?;\n\n        if len.get() == 1 && idx != 0 {\n            bail!(\"there is only one window in this container\");\n        }\n\n        if container.windows().get(idx).is_none() {\n            bail!(\"there is no window in this container at index {idx}\");\n        }\n\n        container.focus_window(idx);\n        container.load_focused_window();\n\n        if let Some(window) = container.focused_window() {\n            window.focus(self.mouse_follows_focus)?;\n        }\n\n        self.update_focused_workspace(self.mouse_follows_focus, true)\n    }\n\n    #[tracing::instrument(skip(self))]\n    pub fn stack_all(&mut self) -> eyre::Result<()> {\n        self.handle_unmanaged_window_behaviour()?;\n        tracing::info!(\"stacking all windows on workspace\");\n\n        let workspace = self.focused_workspace_mut()?;","sourceCodeStart":2743,"sourceCodeEnd":2779,"githubUrl":"https://github.com/LGUG2Z/komorebi/blob/e0709f02bfae4e503bf4640f58ee75ecbbfdbb97/komorebi/src/window_manager.rs#L2743-L2779","documentation":"focus_container_window validates that the requested idx exists in container.windows(); when windows().get(idx) is None the command fails with this formatted message including the bad index. It guards against out-of-bounds focus targets on any container size.","triggerScenarios":"Calling focus_container_window with an idx >= container.windows().len() (or negative where applicable) — e.g. focusing index 3 in a two-window container.","commonSituations":"Nth-window hotkeys (komorebic focus-container-window N) pressed when fewer windows are stacked; generated scripts using stale window counts after windows closed.","solutions":["Query the container's current window count and clamp idx before calling","Refresh state before scripted index-based focus so counts are current","Prefer relative cycling (cycle_container_window_in_direction) over absolute indexes","Catch the error and fall back to focusing index 0"],"exampleFix":"// before\nkomorebic focus-container-window $IDX // IDX may exceed count\n// after\nCOUNT=$(komorebic query focused-container-length 2>/dev/null || echo 1)\n[ \"$IDX\" -lt \"$COUNT\" ] && komorebic focus-container-window \"$IDX\" || komorebic focus-container-window 0","handlingStrategy":"validation","validationCode":"let count = query_focused_container_window_count();\nif idx < count { komorebic focus-container-window idx } else { komorebic focus-container-window 0 }","typeGuard":null,"tryCatchPattern":"// fallback pattern\nmatch focus_container_window(idx) {\n    Err(_) => focus_container_window(0),\n    ok => ok,\n}","preventionTips":["Refresh state before index-based focus so counts are current","Prefer relative cycling over absolute indexes","Fall back to index 0 on failure"],"tags":["windows","window-manager","container","index-out-of-bounds"],"backgroundTag":"index-out-of-range","analyzedSha":"e0709f02bfae4e503bf4640f58ee75ecbbfdbb97","analyzedAt":"2026-09-06T07:08:05.107Z","contentChangedAt":"2026-09-06T07:08:05.107Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}