[BUG] Desktop app panics on window creation failure in headless environments
Problem
The desktop app will crash with a panic when window creation fails:
File: apps/desktop/src/main.rs:50
cx.open_window(
WindowOptions { ... },
|_, cx| { ... }
)
.expect("failed to open the main window");
Scenarios Where It Breaks
- Running in CI/headless environment (no display server)
- SSH session without X forwarding
- Display server unavailable (Wayland/X11 connection fails)
- GPU initialization errors
- System resource exhaustion
Root Cause
Using .expect() on a Result causes panic on Err instead of graceful error handling.
Expected Behavior
Application should:
- Return proper error instead of panicking
- Provide fallback mode for headless execution
- Display user-friendly error message
Recommended Fix
Replace .expect() with proper error handling:
cx.open_window(...)?
Or with explicit error handling:
cx.open_window(...).map_err(|e| {
eprintln!("Failed to open window: {}", e);
e
})?
Detection Method: Static code analysis Severity: Critical (blocks headless/CI usage)
This is a known behavior of GPUI apps when open_window is called without an active windowing context (e.g. in CI or headless environments). Replacing the .expect with a fallback or a clean error exit would prevent the ugly panic stack trace.
I've implemented a fix on my fork (jigglu/OpenCut @ fix/easy-contributions) that maps the window creation failure to a clean exit code and logs a user-friendly error instead of panicking. If you decide to open the repo to community PRs, I can submit this.
Thanks @jigglu Actually I originally reported this issue and have a fix ready to submit.
Happy to open a PR as soon as outside contributions are welcome @maintainer could you let us know when the repo is open for community PRs?
I've addressed this on my fork:
- Branch:
fix/desktop-window-open-graceful-exit - Commit:
ab0694c
Changes
Replaced cx.open_window(...).expect(...) with if let Err(e) = ... logging to stderr and exiting cleanly via cx.quit(). This prevents an uncontrolled panic crash in headless, SSH, or CI environments without a display server.