libnyanpasu/clash-nyanpasu · warning · 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, set_traffic_lights_pos navigates two superview levels up to reach AppKit's private title bar container view (NSTitlebarContainerView). If either superview is nil, the code fails with this error. The title bar container is an undocumented view hierarchy detail, so this breaks when AppKit changes the hierarchy or the window is styled differently.
Source
Thrown at backend/tauri/src/window.rs:925
pos: Position,
) -> 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 + pos.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
- Walk the superview chain searching for the NSTitlebarContainerView class instead of assuming a fixed two-level depth
- Guard with respondsToSelector/class checks and skip repositioning gracefully on hierarchy mismatch
- Pin behavior per macOS version and test on each supported release after upgrades
- If the hierarchy lookup fails, fall back to not adjusting traffic lights (log a warning)
Example fix
// before
let title_bar_container_view = unsafe {
close.superview().and_then(|view| view.superview())
.ok_or(anyhow::anyhow!("failed to get title bar container view"))?
};
// after
let title_bar_container_view = unsafe {
let mut v = close.superview();
while let Some(view) = v {
if view.is_kind_of::<objc2_app_kit::NSTitlebarContainerView>() { break; }
v = view.superview();
}
v.ok_or_else(|| anyhow::anyhow!("NSTitlebarContainerView not found in superview chain"))?
}; Defensive patterns
Strategy: try-catch
Validate before calling
// verify the expected superview depth before casting
let container = close.superview().and_then(|v| v.superview());
if container.is_none() {
return Ok(()); // hierarchy not as expected
} Type guard
fn is_titlebar_container(view: &objc2_runtime::AnyObject) -> bool {
unsafe { view.is_kind_of::<objc2_app_kit::NSTitlebarContainerView>() }
} Try / catch
if let Err(e) = set_traffic_lights_pos(window, pos) {
log::warn!("traffic light positioning unavailable (AppKit hierarchy changed?): {e}");
} Prevention
- Search the superview chain by class rather than fixed depth — AppKit may change the hierarchy
- Re-test private-view navigation after every macOS upgrade
- Treat title-bar container manipulation as best-effort; never fail window creation on it
When it happens
Trigger: set_traffic_lights_pos called on a window whose close button has no two-level superview chain — undecorated/overlay title bars, macOS versions where NSTitlebarContainerView is absent (no titlebar), or bridged views from a non-standard window setup.
Common situations: macOS version upgrades changing the private view hierarchy; Tauri titleBarStyle overlay windows; windows in fullscreen where the titlebar container is detached; very new macOS releases where the private class layout differs.
Related errors
- failed to get close button
- failed to get miniaturize button
- failed to get zoom button
- failed to get title bar container view
- failed to get close button
AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08).
Data as JSON: /api/errors/06303f2be5df2f5d.
Report an issue: GitHub.