{"record":{"id":"deb2fca2f19906de","repo":"lencx/ChatGPT","slug":"core-window-failed-to-build-window","errorCode":null,"errorMessage":"[core:window] Failed to build window","messagePattern":"\\[core:window\\] Failed to build window","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src-tauri/src/core/setup.rs","lineNumber":48,"sourceCode":"        async move {\n            let mut core_window = WindowBuilder::new(&handle, \"core\").title(\"ChatGPT\");\n\n            #[cfg(target_os = \"macos\")]\n            {\n                core_window = core_window\n                    .title_bar_style(TitleBarStyle::Overlay)\n                    .hidden_title(true);\n            }\n\n            core_window = core_window\n                .resizable(true)\n                .inner_size(800.0, 600.0)\n                .min_inner_size(300.0, 200.0)\n                .theme(Some(AppConf::get_theme(&handle)));\n\n            let core_window = core_window\n                .build()\n                .expect(\"[core:window] Failed to build window\");\n\n            let win_size = core_window\n                .inner_size()\n                .expect(\"[core:window] Failed to get window size\");\n            // Wrap the window in Arc<Mutex<_>> to manage ownership across threads\n            let window = Arc::new(Mutex::new(core_window));\n\n            let main_view =\n                WebviewBuilder::new(\"main\", WebviewUrl::App(\"https://chatgpt.com\".into()))\n                    .auto_resize()\n                    .on_download({\n                        let app_handle = handle.clone();\n                        let download_path = Arc::new(Mutex::new(PathBuf::new()));\n                        move |_, event| {\n                            match event {\n                                DownloadEvent::Requested { destination, .. } => {\n                                    let download_dir = app_handle\n                                        .path()","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/lencx/ChatGPT/blob/a6de9a8b61077fa63ad5c3ecbe2bc12e0cb4b4b9/src-tauri/src/core/setup.rs#L30-L66","documentation":"Panic from WindowBuilder::build() (tauri::WebviewWindowBuilder/WindowBuilder) returning Err. build() creates the OS-native window and registers it under the label \"core\"; it fails when the label is already taken, the event loop is gone, or the platform rejects window creation (display server error, invalid theme/size params). The .expect() then panics inside the tauri::async_runtime::spawn task, so no window ever appears.","triggerScenarios":"Calling WindowBuilder::new(&handle, \"core\")...build() twice with the same label (double init, hot-reload in `tauri dev` re-running setup, single-instance plugin disabled and a second instance starting); running on Linux under a broken display session (XDG_SESSION_TYPE unset, Wayland compositor crash); passing a theme value the platform cannot honor.","commonSituations":"Developers adding a second window in setup and reusing the label \"core\"; enabling the single-instance plugin incorrectly so a second app instance runs setup again; Linux CI/headless environments with no display; upgrading tauri v1->v2 where builder APIs changed and setup code is invoked from both the old and new hook.","solutions":["Make the label unique or bail out if a window labeled \"core\" already exists (check handle.get_webview_window(\"core\") before building)","Replace .expect() with match/if-let on the Err and log the underlying error (it carries the real cause, e.g. \"label already exists\" or display error)","Ensure the single-instance plugin (tauri-plugin-single-instance) is registered so a second launch shows the first window instead of re-running setup","On Linux, verify the session has a working display (echo $XDG_SESSION_TYPE, run under X11/XWayland if the compositor is unstable)"],"exampleFix":"// before\nlet core_window = core_window\n    .build()\n    .expect(\"[core:window] Failed to build window\");\n\n// after\nlet core_window = match core_window.build() {\n    Ok(w) => w,\n    Err(e) => {\n        eprintln!(\"[core:window] Failed to build window: {e}\");\n        return;\n    }\n};","handlingStrategy":"try-catch","validationCode":"// before building: ensure the label is free\nif handle.get_webview_window(\"core\").is_some() {\n    eprintln!(\"[core:window] label 'core' already exists; skipping build\");\n    return;\n}","typeGuard":"fn core_window_absent(handle: &tauri::AppHandle) -> bool {\n    handle.get_webview_window(\"core\").is_none()\n}","tryCatchPattern":"let core_window = match core_window.build() {\n    Ok(w) => w,\n    Err(e) => {\n        eprintln!(\"[core:window] Failed to build window: {e}\");\n        return;\n    }\n};","preventionTips":["Register tauri-plugin-single-instance so setup never runs twice","Keep window labels in one constant/module to avoid duplicates","Never .expect() on build(); propagate or log-and-return from the async task"],"tags":["tauri","window","rust","panic","startup"],"backgroundTag":null,"analyzedSha":"a6de9a8b61077fa63ad5c3ecbe2bc12e0cb4b4b9","analyzedAt":"2026-08-16T08:31:13.240Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}