libnyanpasu/clash-nyanpasu · error · anyhow::Error

failed to get close button

Error message

failed to get close button

What it means

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.

Source

Thrown at backend/tauri/src/utils/resolve.rs:73

fn ignore_tray_menu_blur_for(duration_ms: u64) {
    TRAY_MENU_IGNORE_BLUR_UNTIL_MS.store(
        unix_time_millis().saturating_add(duration_ms),
        Ordering::Release,
    );
}

#[cfg(target_os = "macos")]
fn set_window_controls_pos(
    window: objc2::rc::Retained<objc2_app_kit::NSWindow>,
    x: f64,
    y: f64,
) -> anyhow::Result<()> {
    use objc2_app_kit::NSWindowButton;
    use objc2_foundation::NSRect;
    let close = window
        .standardWindowButton(NSWindowButton::CloseButton)
        .ok_or(anyhow::anyhow!("failed to get close button"))?;
    let miniaturize = window
        .standardWindowButton(NSWindowButton::MiniaturizeButton)
        .ok_or(anyhow::anyhow!("failed to get miniaturize button"))?;
    let zoom = window
        .standardWindowButton(NSWindowButton::ZoomButton)
        .ok_or(anyhow::anyhow!("failed to get zoom button"))?;

    let title_bar_container_view = unsafe {
        close
            .superview()
            .and_then(|view| view.superview())
            .ok_or(anyhow::anyhow!("failed to get title bar container view"))?
    };

    let close_rect = close.frame();
    let button_height = close_rect.size.height;

    let title_bar_frame_height = button_height + y;

View on GitHub (pinned to f7dbce2997)

Solutions

  1. Call set_window_controls_pos after the window is created and shown (e.g. on window ready/event), not before
  2. Check verge/window config: if the traffic-light buttons were hidden, restore them before repositioning
  3. Guard the call: skip repositioning (log a warning) when buttons are intentionally hidden
  4. Ensure the call is only executed on macOS targets

Example fix

// before
set_window_controls_pos(&win, x, y).await?;
// after: tolerate missing buttons
if let Err(e) = set_window_controls_pos(&win, x, y).await {
    log::warn!("skip traffic-light reposition: {e}");
}
Defensive patterns

Strategy: fallback

Validate before calling

if window.standardWindowButton(NSWindowButton::CloseButton).is_none() {
    log::warn!("traffic light buttons unavailable; skip reposition");
    return Ok(());
}

Try / catch

if let Err(e) = set_window_controls_pos(&win, x, y).await {
    log::warn!("traffic-light reposition skipped: {e:#}");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08). Data as JSON: /api/errors/aa545a362ca0a1c0. Report an issue: GitHub.