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

failed to get miniaturize button

Error message

failed to get miniaturize button

What it means

Same mechanism as the close-button failure: standardWindowButton(NSWindowButton::MiniaturizeButton) returned None while repositioning the macOS window control buttons, so the code raises this error. It means AppKit could not provide the minimize button for the window.

Source

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

        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;
    let mut title_bar_rect = title_bar_container_view.frame();
    title_bar_rect.size.height = title_bar_frame_height;
    title_bar_rect.origin.y = window.frame().size.height - title_bar_frame_height;

View on GitHub (pinned to f7dbce2997)

Solutions

  1. Ensure the window's style mask includes miniaturizable before calling
  2. Call after the window is fully created/shown
  3. If buttons are intentionally hidden, skip the call instead of erroring
  4. Fetch all three buttons and log which are missing to diagnose the style-mask issue

Example fix

// before: hard error on any missing button
let miniaturize = window
    .standardWindowButton(NSWindowButton::MiniaturizeButton)
    .ok_or(anyhow::anyhow!("failed to get miniaturize button"))?;
// after: reposition only the buttons that exist
let buttons = [close, miniaturize, zoom].into_iter().flatten();
Defensive patterns

Strategy: fallback

Validate before calling

if window.standardWindowButton(NSWindowButton::MiniaturizeButton).is_none() {
    log::warn!("miniaturize button unavailable; skip reposition");
    return Ok(());
}

Try / catch

match set_window_controls_pos(&win, x, y).await {
    Ok(()) => {},
    Err(e) => log::debug!("button reposition skipped: {e:#}"),
}

Prevention

When it happens

Trigger: Calling set_window_controls_pos on a window created without a miniaturize button (e.g. style mask lacking NSWindowStyleMask::Miniaturizable, or buttons already hidden/removed).

Common situations: Windows configured without minimize capability; calling before window decoration is realized; custom titlebar setups that removed native buttons; macOS-only code path invoked during early setup.

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/2d55ecb1d8f29b91. Report an issue: GitHub.