{"record":{"id":"8b8e2b846087df3c","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-close-button-8b8e2b","errorCode":null,"errorMessage":"failed to get close button","messagePattern":"failed to get close button","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"backend/tauri/src/window.rs","lineNumber":913,"sourceCode":"            }\n        }\n    }\n\n    impl From<Position> for (f64, f64) {\n        fn from(value: Position) -> Self {\n            (value.x, value.y)\n        }\n    }\n\n    fn set_traffic_lights_pos(\n        window: objc2::rc::Retained<objc2_app_kit::NSWindow>,\n        pos: Position,\n    ) -> anyhow::Result<()> {\n        use objc2_app_kit::NSWindowButton;\n        use objc2_foundation::NSRect;\n        let close = window\n            .standardWindowButton(NSWindowButton::CloseButton)\n            .ok_or(anyhow::anyhow!(\"failed to get close button\"))?;\n        let miniaturize = window\n            .standardWindowButton(NSWindowButton::MiniaturizeButton)\n            .ok_or(anyhow::anyhow!(\"failed to get miniaturize button\"))?;\n        let zoom = window\n            .standardWindowButton(NSWindowButton::ZoomButton)\n            .ok_or(anyhow::anyhow!(\"failed to get zoom button\"))?;\n\n        let title_bar_container_view = unsafe {\n            close\n                .superview()\n                .and_then(|view| view.superview())\n                .ok_or(anyhow::anyhow!(\"failed to get title bar container view\"))?\n        };\n\n        let close_rect = close.frame();\n        let button_height = close_rect.size.height;\n\n        let title_bar_frame_height = button_height + pos.y;","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/window.rs#L895-L931","documentation":"set_traffic_lights_pos (macOS) requests the window's standard close button via NSWindow.standardWindowButton(.closeButton). AppKit returned nil, so the code errors with this message. Without the button handle, the traffic-light position cannot be adjusted.","triggerScenarios":"Calling apply_traffic_lights_pos / set_traffic_lights_pos on an NSWindow that has no standard close button — e.g. a borderless (titleBarStyle: Overlay/None) window whose buttons were hidden, a window not yet fully created, or an NSWindowStyleMask without .closable.","commonSituations":"Tauri windows created with decorations=false or decorations:false so AppKit never installs traffic lights; calling the API too early before the window is on-screen; fullscreen spaces where button access is transient; custom title bar replacements hiding the buttons.","solutions":["Create the window with decorations enabled (or .closable in the style mask) so standardWindowButton returns a button","Defer set_traffic_lights_pos until the window is visible/on-screen (e.g. after on_window_event Focus/Resized) and retry once if nil","Hide buttons via button.setHidden instead of removing decorations so handles still exist","Fall back gracefully: log a warning and skip repositioning instead of failing the whole operation"],"exampleFix":"// before\nlet close = window\n    .standardWindowButton(NSWindowButton::CloseButton)\n    .ok_or(anyhow::anyhow!(\"failed to get close button\"))?;\n// after\nlet Some(close) = window.standardWindowButton(NSWindowButton::CloseButton) else {\n    log::warn!(\"window has no standard close button (undecorated?); skipping traffic light reposition\");\n    return Ok(());\n};","handlingStrategy":"fallback","validationCode":"// only reposition when buttons exist\nif window.standardWindowButton(NSWindowButton::CloseButton).is_none() {\n    return Ok(()); // undecorated window; nothing to reposition\n}","typeGuard":"fn has_traffic_lights(window: &NSWindow) -> bool {\n    window.standardWindowButton(NSWindowButton::CloseButton).is_some()\n}","tryCatchPattern":"match apply_traffic_lights_pos(window, pos) {\n    Err(e) => log::warn!(\"traffic light reposition skipped: {e}\"),\n    Ok(()) => {}\n}","preventionTips":["Don't create traffic-light windows with decorations:false if you plan to reposition buttons","Call set_traffic_lights_pos after the window is visible; retry once on failure","Hide buttons with setHidden instead of removing them from the style mask"],"tags":["macos","appkit","window"],"backgroundTag":"window-button-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"}