{"record":{"id":"515e58764fb0f4d7","repo":"libnyanpasu/clash-nyanpasu","slug":"window-not-found","errorCode":null,"errorMessage":"window not found","messagePattern":"window not found","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/window.rs","lineNumber":967,"sourceCode":"        Ok(())\n    }\n\n    #[derive(Debug, Clone)]\n    struct WindowState {\n        window: WebviewWindow<tauri::Wry>,\n        traffic_lights_pos: Position,\n    }\n\n    impl WindowState {\n        fn new(window: WebviewWindow<tauri::Wry>, traffic_lights_pos: Position) -> Self {\n            Self {\n                window,\n                traffic_lights_pos,\n            }\n        }\n\n        fn with_ns_window<T>(&self, func: impl FnOnce(Retained<NSWindow>) -> T) -> T {\n            let ns_window = self.window.ns_window().expect(\"window not found\");\n            let ns_window = unsafe { Retained::retain_autoreleased(ns_window as *mut NSWindow) }\n                .expect(\"failed to retain window\");\n            func(ns_window)\n        }\n\n        fn apply_traffic_lights_pos(&self) {\n            self.with_ns_window(|win| {\n                set_traffic_lights_pos(win, self.traffic_lights_pos)\n                    .expect(\"failed to set traffic lights pos\");\n            });\n        }\n    }\n\n    #[derive(Debug)]\n    struct TrafficLightsWindowDelegateIvars {\n        app_box: WindowState,\n        super_class: Retained<ProtocolObject<dyn NSWindowDelegate>>,\n    }","sourceCodeStart":949,"sourceCodeEnd":985,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/window.rs#L949-L985","documentation":"`with_ns_window` calls Tauri's `WebviewWindow::ns_window()` and expects to get the raw `*mut NSWindow`. The panic means Tauri could not return the native macOS window pointer — usually the window is not a real NSWindow-backed window (wrong window type or already destroyed) or the call is made off the main thread. This macOS-only helper then cannot apply traffic-light positioning.","triggerScenarios":"Calling `apply_traffic_lights_pos`/`with_ns_window` on a window whose underlying platform window is gone (window closed/closing during a callback), a window created as a non-NSWindow type, or `ns_window()` invoked outside the main thread.","commonSituations":"Traffic-light position restoration racing window close during app shutdown or workspace switching; delegate callbacks firing after `window.close()`; running logic on a background thread without dispatching to the main thread.","solutions":["Check that the window still exists (e.g. `get_webview_window` returns Some) before calling `with_ns_window`, and skip silently otherwise.","Dispatch all NSWindow access to the main thread (`MainThreadMarker`/`performOnMainThread`) as required by AppKit.","Guard the call against the window-closing state (e.g. skip traffic-light work in delegate callbacks after close).","Replace `.expect` with a `Result` return so callers can degrade instead of panicking."],"exampleFix":"// before\nlet ns_window = self.window.ns_window().expect(\"window not found\");\n// after\nlet Ok(ns_window) = self.window.ns_window() else {\n    tracing::warn!(\"ns_window unavailable; skipping traffic light update\");\n    return Default::default();\n};","handlingStrategy":"fallback","validationCode":"if window.as_ref().map(|w| w.is_visible()).unwrap_or(false) != true {\n    tracing::warn!(\"window gone or hidden; skipping ns_window access\");\n}","typeGuard":"fn has_ns_window(window: &WebviewWindow) -> bool {\n    window.is_visible().unwrap_or(false)\n        && window.ns_window().is_ok()\n}","tryCatchPattern":"let Ok(ns_window) = self.window.ns_window() else {\n    tracing::warn!(\"ns_window unavailable; skipping\");\n    return Default::default();\n};","preventionTips":["Dispatch all NSWindow access onto the main thread","Skip traffic-light work in callbacks that may fire after window close","Check window liveness (get_webview_window) before native access"],"tags":["macos","tauri","nswindow","panic"],"backgroundTag":"resource-not-found","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}