{"record":{"id":"b8ecd7f765fea339","repo":"zed-industries/zed","slug":"dialog-cancelled","errorCode":null,"errorMessage":"dialog cancelled","messagePattern":"dialog cancelled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/gpui_windows/src/dialog.rs","lineNumber":122,"sourceCode":"                    Either::Right(((), _)) => return,\n                }\n            } else {\n                None\n            };\n            if sender.is_canceled() || cancellation.is_requested() {\n                return;\n            }\n            let (result_sender, mut result_receiver) = oneshot::channel();\n            let thread = std::thread::Builder::new()\n                .name(\"windows-native-dialog\".into())\n                .spawn({\n                    let cancellation = cancellation.clone();\n                    move || {\n                        let result = (|| {\n                            let _apartment = Apartment::new()?;\n                            let _timer = CancellationTimer::new(cancellation.clone())?;\n                            if cancellation.is_requested() {\n                                return Err(anyhow!(\"dialog cancelled\"));\n                            }\n                            let result = dialog(hwnd.map(|hwnd| hwnd.as_raw()).unwrap_or_default());\n                            if cancellation.is_requested() {\n                                return Err(anyhow!(\"dialog cancelled\"));\n                            }\n                            result\n                        })();\n                        result_sender.send(result).ok();\n                    }\n                });\n            if let Err(error) = thread {\n                drop(serialization);\n                sender.send(Err(error.into())).ok();\n                return;\n            }\n            let result = match select(&mut result_receiver, sender.cancellation()).await {\n                Either::Left((result, _)) => result,\n                Either::Right(((), _)) => {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui_windows/src/dialog.rs#L104-L140","documentation":"show_dialog runs the platform dialog on a background thread and can be cancelled (e.g. the window was closed or a timeout fired via CancellationTimer). Before and after invoking the dialog callback, the thread checks the cancellation token; if cancellation was requested it aborts with this anyhow error instead of returning dialog results. It is a deliberate cooperative-cancellation signal, not a bug.","triggerScenarios":"Calling show_dialog and then closing the window / dropping the requester before the background thread reaches the dialog callback (pre-dialog check at line 122), or the CancellationTimer expiring while the dialog is being spawned.","commonSituations":"Rapidly closing a window while a file-picker or message box is still opening; slow COM apartment startup on a busy system; teardown races during app shutdown where the dialog request outlives its owner.","solutions":["Treat the error as benign cancellation: filter it out where dialog results are consumed instead of logging it as a failure.","Avoid closing/dropping the window that owns the dialog request until the dialog future resolves, or keep a handle so cancellation is intentional.","If it fires frequently at startup, investigate slow Apartment::new / thread startup that widens the cancellation race window.","Check whether CancellationTimer's timeout is too aggressive for the environment and raise it if dialogs legitimately take long."],"exampleFix":"// before\nif let Err(e) = show_dialog(...).await {\n    log::error!(\"dialog failed: {e}\");\n}\n// after\nif let Err(e) = show_dialog(...).await {\n    if !e.to_string().contains(\"dialog cancelled\") {\n        log::error!(\"dialog failed: {e}\");\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match show_dialog(cx).await {\n    Ok(result) => handle(result),\n    Err(e) if e.to_string().contains(\"dialog cancelled\") => {}, // benign\n    Err(e) => log::error!(\"dialog failed: {e:#}\"),\n}","preventionTips":["Keep the owning window alive until the dialog future resolves","Treat 'dialog cancelled' as a normal control-flow outcome, not a failure","Avoid spawning dialogs during app shutdown sequences"],"tags":["windows","dialog","cancellation","race-condition"],"backgroundTag":"thread-interrupted","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}