LGUG2Z/komorebi · error
this is not a valid monitor index
Error message
this is not a valid monitor index
What it means
focus_monitor validates the requested monitor index against the number of entries in self.monitors. If monitors.get(idx) is None — the index exceeds the connected/virtual monitor count — the command fails with this message instead of panicking on an out-of-bounds access.
Source
Thrown at komorebi/src/window_manager.rs:3702
.ok_or_eyre("there is no monitor")?
.size)
}
pub fn focused_monitor_work_area(&self) -> eyre::Result<Rect> {
Ok(self
.focused_monitor()
.ok_or_eyre("there is no monitor")?
.work_area_size)
}
#[tracing::instrument(skip(self))]
pub fn focus_monitor(&mut self, idx: usize) -> eyre::Result<()> {
tracing::info!("focusing monitor");
if self.monitors().get(idx).is_some() {
self.monitors.focus(idx);
} else {
bail!("this is not a valid monitor index");
}
Ok(())
}
pub fn monitor_idx_from_window(&mut self, window: Window) -> Option<usize> {
let hmonitor = WindowsApi::monitor_from_window(window.hwnd);
for (i, monitor) in self.monitors().iter().enumerate() {
if monitor.id == hmonitor {
return Option::from(i);
}
}
// our hmonitor might be stale, so if we didn't return above, try querying via the latest
// info taken from win32_display_data and update our hmonitor while we're at it
if let Ok(latest) = WindowsApi::monitor(hmonitor) {
for (i, monitor) in self.monitors_mut().iter_mut().enumerate() {View on GitHub (pinned to e0709f02bf)
Solutions
- Query the current monitor count (komorebic query state / OS APIs) and clamp the index before calling focus_monitor
- Use relative cycling (komorebic cycle-monitor) instead of absolute indexes
- Regenerate or parameterize configs per machine rather than hardcoding monitor indexes
- Catch the error and fall back to the primary monitor
Example fix
// before komorebic focus-monitor 2 // fails on 2-monitor setup (indexes 0..1) // after komorebic cycle-monitor # relative cycling avoids out-of-range indexes
Defensive patterns
Strategy: validation
Validate before calling
let monitor_count = query_korebi_monitor_count(); // e.g. via komorebic query
if idx < monitor_count { komorebic focus-monitor idx }
else { komorebic focus-monitor 0 } Try / catch
// fallback to primary monitor
match wm.focus_monitor(idx) {
Err(_) => wm.focus_monitor(0),
ok => ok,
} Prevention
- Never hardcode monitor indexes in shared configs; compute from the live monitor count
- Handle monitor hotplug events by refreshing saved indexes
- Prefer cycle-monitor (relative) over absolute indexes
When it happens
Trigger: Calling focus_monitor(idx) (komorebic focus-monitor N, monitor cycling with saved configs) where idx >= monitors.len(), e.g. index 2 on a single-monitor setup, or after a monitor was disconnected.
Common situations: Sharing komorebi.json keybinds across machines with different monitor counts; hotplug changes (undocking a laptop) invalidating previously valid indexes; scripts with hardcoded indexes.
Related errors
- there is no window in this container at index {idx}
- cannot move native maximized window to another monitor or wo
- failed to find a window to move
- ignoring command while active window is in monocle mode or m
- there is only one window in this container
AI-assisted analysis of LGUG2Z/komorebi@e0709f02bf (2026-09-06).
Data as JSON: /api/errors/421332fb213ecec7.
Report an issue: GitHub.