{"record":{"id":"aa545a362ca0a1c0","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-close-button","errorCode":null,"errorMessage":"failed to get close button","messagePattern":"failed to get close button","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/resolve.rs","lineNumber":73,"sourceCode":"\nfn ignore_tray_menu_blur_for(duration_ms: u64) {\n    TRAY_MENU_IGNORE_BLUR_UNTIL_MS.store(\n        unix_time_millis().saturating_add(duration_ms),\n        Ordering::Release,\n    );\n}\n\n#[cfg(target_os = \"macos\")]\nfn set_window_controls_pos(\n    window: objc2::rc::Retained<objc2_app_kit::NSWindow>,\n    x: f64,\n    y: f64,\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 + y;","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/resolve.rs#L55-L91","documentation":"set_window_controls_pos repositions the macOS traffic-light window buttons. NSWindow.standardWindowButton(_:) can return nil (Optional), so when AppKit fails to hand back the close button the code converts that None into this anyhow error. It only occurs on macOS when the standard window buttons are unavailable.","triggerScenarios":"Calling set_window_controls_pos on a window whose standardWindowButton(NSWindowButton::CloseButton) returns None — typically before the window is fully created/shown, after the buttons were hidden or removed, or for a window style without standard buttons.","commonSituations":"Calling the function too early in window setup on macOS; hiddenTitleBar / custom titlebar config stripping the buttons; window not yet on-screen; running on a non-macOS path compiled in accidentally.","solutions":["Call set_window_controls_pos after the window is created and shown (e.g. on window ready/event), not before","Check verge/window config: if the traffic-light buttons were hidden, restore them before repositioning","Guard the call: skip repositioning (log a warning) when buttons are intentionally hidden","Ensure the call is only executed on macOS targets"],"exampleFix":"// before\nset_window_controls_pos(&win, x, y).await?;\n// after: tolerate missing buttons\nif let Err(e) = set_window_controls_pos(&win, x, y).await {\n    log::warn!(\"skip traffic-light reposition: {e}\");\n}","handlingStrategy":"fallback","validationCode":"if window.standardWindowButton(NSWindowButton::CloseButton).is_none() {\n    log::warn!(\"traffic light buttons unavailable; skip reposition\");\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = set_window_controls_pos(&win, x, y).await {\n    log::warn!(\"traffic-light reposition skipped: {e:#}\");\n}","preventionTips":["Only call after the window is shown and fully realized","Keep standard buttons attached when using custom titlebars, or skip repositioning when hidden","Guard macOS-only code with cfg(target_os = \"macos\") and runtime OS checks"],"tags":["macos","window","appkit","traffic-light-buttons"],"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"}