libnyanpasu/clash-nyanpasu · error · anyhow::Error
failed to get title bar container view
Error message
failed to get title bar container view
What it means
After obtaining the close button, the function walks its view hierarchy two levels up (close.superview().and_then(|v| v.superview())) to reach the title bar container view (NSTitlebarContainerView). If either superview is nil it raises this error, meaning the expected AppKit private view hierarchy does not match.
Source
Thrown at backend/tauri/src/utils/resolve.rs:85
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;
unsafe {
title_bar_container_view.setFrame(title_bar_rect);
}
let space_between = miniaturize.frame().origin.x - close.frame().origin.x;
let window_buttons = vec![close, miniaturize, zoom];
for (i, button) in window_buttons.into_iter().enumerate() {
let mut rect: NSRect = button.frame();View on GitHub (pinned to f7dbce2997)
Solutions
- Verify the call runs after the window is visible so the view hierarchy is built
- Instead of relying on superview count, walk up the hierarchy and match the view class (NSTitlebarContainerView)
- Add a macOS-version guard or fallback that skips repositioning on unexpected hierarchies
- Log the intermediate superview classes when this fails to diagnose layout differences
Example fix
// before: fixed two-level superview walk
close.superview().and_then(|v| v.superview()).ok_or(...)?
// after: match the container class while walking up
let mut v = close.superview();
while let Some(view) = v {
if view.className().contains("TitlebarContainer") { break; }
v = view.superview();
}
v.ok_or_else(|| anyhow::anyhow!("failed to get title bar container view"))? Defensive patterns
Strategy: fallback
Validate before calling
// pre-check the hierarchy depth before mutating layout
let has_container = close.superview()
.and_then(|v| v.superview())
.is_some();
if !has_container { log::warn!("title bar container missing; skip"); return Ok(()); } Try / catch
if let Err(e) = set_window_controls_pos(&win, x, y).await {
log::warn!("titlebar customization skipped: {e:#}");
} Prevention
- Walk the superview chain by class name instead of a fixed number of levels
- Pin/test against macOS versions you support; private view hierarchies change
- Only run after the window is visible and laid out
When it happens
Trigger: Calling set_window_controls_pos when the close button is not nested in the standard two-level title bar container — e.g. macOS version changes to the title bar hierarchy, a custom titlebar implementation, or the window uses a non-standard style.
Common situations: New macOS releases restructuring private view hierarchies; windows with full-size content view / custom titlebars; calling before the view hierarchy is laid out; utility or borderless windows.
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
- failed to get close button
- failed to get miniaturize button
- failed to get zoom button
- failed to get close button
- failed to get miniaturize button
AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08).
Data as JSON: /api/errors/b90b2710671f608d.
Report an issue: GitHub.