{"record":{"id":"b90b2710671f608d","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-title-bar-container-view","errorCode":null,"errorMessage":"failed to get title bar container view","messagePattern":"failed to get title bar container view","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/resolve.rs","lineNumber":85,"sourceCode":"    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;\n    let mut title_bar_rect = title_bar_container_view.frame();\n    title_bar_rect.size.height = title_bar_frame_height;\n    title_bar_rect.origin.y = window.frame().size.height - title_bar_frame_height;\n    unsafe {\n        title_bar_container_view.setFrame(title_bar_rect);\n    }\n\n    let space_between = miniaturize.frame().origin.x - close.frame().origin.x;\n    let window_buttons = vec![close, miniaturize, zoom];\n\n    for (i, button) in window_buttons.into_iter().enumerate() {\n        let mut rect: NSRect = button.frame();","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/resolve.rs#L67-L103","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: fixed two-level superview walk\nclose.superview().and_then(|v| v.superview()).ok_or(...)?\n// after: match the container class while walking up\nlet mut v = close.superview();\nwhile let Some(view) = v {\n    if view.className().contains(\"TitlebarContainer\") { break; }\n    v = view.superview();\n}\nv.ok_or_else(|| anyhow::anyhow!(\"failed to get title bar container view\"))?","handlingStrategy":"fallback","validationCode":"// pre-check the hierarchy depth before mutating layout\nlet has_container = close.superview()\n    .and_then(|v| v.superview())\n    .is_some();\nif !has_container { log::warn!(\"title bar container missing; skip\"); return Ok(()); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = set_window_controls_pos(&win, x, y).await {\n    log::warn!(\"titlebar customization skipped: {e:#}\");\n}","preventionTips":["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"],"tags":["macos","appkit","view-hierarchy","titlebar"],"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"}