OpenCut icon indicating copy to clipboard operation
OpenCut copied to clipboard

[BUG] Desktop app panics on window creation failure in headless environments

Open kapil971390 opened this issue 4 months ago • 3 comments

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)

kapil971390 avatar Jul 14 '26 08:07 kapil971390

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.

jigglu avatar Jul 15 '26 16:07 jigglu

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?

kapil971390 avatar Jul 15 '26 17:07 kapil971390

I've addressed this on my fork:

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.

killer1panda avatar Sep 08 '26 07:09 killer1panda