LGUG2Z/komorebi · error

there is no window in this container at index {idx}

Error message

there is no window in this container at index {idx}

What it means

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.

Source

Thrown at komorebi/src/window_manager.rs:2761

        tracing::info!("focusing container window at index {idx}");

        let container =
            if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
                container
            } else {
                self.focused_container_mut()?
            };

        let len = NonZeroUsize::new(container.windows().len())
            .ok_or_eyre("there must be at least one window in a container")?;

        if len.get() == 1 && idx != 0 {
            bail!("there is only one window in this container");
        }

        if container.windows().get(idx).is_none() {
            bail!("there is no window in this container at index {idx}");
        }

        container.focus_window(idx);
        container.load_focused_window();

        if let Some(window) = container.focused_window() {
            window.focus(self.mouse_follows_focus)?;
        }

        self.update_focused_workspace(self.mouse_follows_focus, true)
    }

    #[tracing::instrument(skip(self))]
    pub fn stack_all(&mut self) -> eyre::Result<()> {
        self.handle_unmanaged_window_behaviour()?;
        tracing::info!("stacking all windows on workspace");

        let workspace = self.focused_workspace_mut()?;

View on GitHub (pinned to e0709f02bf)

Solutions

  1. Query the container's current window count and clamp idx before calling
  2. Refresh state before scripted index-based focus so counts are current
  3. Prefer relative cycling (cycle_container_window_in_direction) over absolute indexes
  4. Catch the error and fall back to focusing index 0

Example fix

// before
komorebic focus-container-window $IDX // IDX may exceed count
// after
COUNT=$(komorebic query focused-container-length 2>/dev/null || echo 1)
[ "$IDX" -lt "$COUNT" ] && komorebic focus-container-window "$IDX" || komorebic focus-container-window 0
Defensive patterns

Strategy: validation

Validate before calling

let count = query_focused_container_window_count();
if idx < count { komorebic focus-container-window idx } else { komorebic focus-container-window 0 }

Try / catch

// fallback pattern
match focus_container_window(idx) {
    Err(_) => focus_container_window(0),
    ok => ok,
}

Prevention

When it happens

Trigger: Calling focus_container_window with an idx >= container.windows().len() (or negative where applicable) — e.g. focusing index 3 in a two-window container.

Common situations: Nth-window hotkeys (komorebic focus-container-window N) pressed when fewer windows are stacked; generated scripts using stale window counts after windows closed.

Related errors


AI-assisted analysis of LGUG2Z/komorebi@e0709f02bf (2026-09-06). Data as JSON: /api/errors/f83739370ef3e872. Report an issue: GitHub.