{"record":{"id":"c7524b69d6bc597c","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-set-traffic-lights-pos","errorCode":null,"errorMessage":"failed to set traffic lights pos","messagePattern":"failed to set traffic lights pos","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/tauri/src/window.rs","lineNumber":976,"sourceCode":"    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    }\n\n    const WINDOW_DID_ENTER_FULL_SCREEN: &str = \"internal:://window-did-enter-full-screen\";\n    const WINDOW_WILL_ENTER_FULL_SCREEN: &str = \"internal:://window-will-enter-full-screen\";\n    const WINDOW_WILL_EXIT_FULL_SCREEN: &str = \"internal:://window-will-exit-full-screen\";\n    const WINDOW_DID_EXIT_FULL_SCREEN: &str = \"internal:://window-did-exit-full-screen\";\n\n    define_class! {\n        #[unsafe(super(NSObject))]\n        #[name = \"TrafficLightsPosWindowDelegate\"]","sourceCodeStart":958,"sourceCodeEnd":994,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/window.rs#L958-L994","documentation":"Inside `apply_traffic_lights_pos`, the helper `set_traffic_lights_pos` (which manipulates the NSWindow's standard window buttons via objc calls) has its Result discarded with this expect. The panic means the AppKit manipulation failed — the standard window buttons (close/minimize/zoom) were absent or the objc message returned an error. This is a cosmetic macOS customization failing hard instead of degrading.","triggerScenarios":"Calling `apply_traffic_lights_pos` on a window whose titlebar buttons were not created (custom titlebar styles, fullscreen transitions, window mid-close), or `set_traffic_lights_pos` returning Err from a failed objc2 method call.","commonSituations":"Applying saved traffic-light positions at startup before AppKit finishes building buttons; toggling `titleBarStyle`/`hiddenTitle` at runtime; fullscreen enter/exit invalidating the button handles; restored windows on macOS during state restoration.","solutions":["Retry the positioning after a short main-thread dispatch or on the window's `did-resize`/`did-become-visible` event when buttons exist.","Return/log the error instead of expecting so a cosmetic failure never crashes the app: `let _ = set_traffic_lights_pos(win, pos);` with a warn log.","Check the window's titlebar style configuration — positions cannot be applied when standard buttons are hidden.","Verify the saved `traffic_lights_pos` values are sane offsets; clamp before applying."],"exampleFix":"// before\nset_traffic_lights_pos(win, self.traffic_lights_pos)\n    .expect(\"failed to set traffic lights pos\");\n// after\nif let Err(e) = set_traffic_lights_pos(win, self.traffic_lights_pos) {\n    tracing::warn!(\"failed to set traffic lights pos: {e}\");\n}","handlingStrategy":"fallback","validationCode":"// ensure standard buttons exist before positioning\nif win.standardWindowButton(NSWindowButton::CloseButton).is_none() {\n    tracing::warn!(\"standard buttons missing; skip traffic light pos\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = set_traffic_lights_pos(win, self.traffic_lights_pos) {\n    tracing::warn!(\"failed to set traffic lights pos: {e}\");\n}","preventionTips":["Apply positions after the window is fully shown, not during construction","Clamp saved traffic-light offsets to sane values","Treat traffic-light styling as best-effort cosmetic; never panic on it"],"tags":["macos","objc2","ui","panic"],"backgroundTag":"objc-call-failed","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"}