{"record":{"id":"8141e3604975117e","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-get-tray-menu-window","errorCode":null,"errorMessage":"failed to get tray menu window","messagePattern":"failed to get tray menu window","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/resolve.rs","lineNumber":599,"sourceCode":"            }\n        }\n        _ => {}\n    });\n}\n\n/// Create a persistent tray menu window for debugging.\npub fn create_debug_tray_menu_window(app_handle: &AppHandle) -> Result<()> {\n    TRAY_MENU_PERSISTENT.store(true, Ordering::Release);\n    ignore_tray_menu_blur_for(TRAY_MENU_SHOW_BLUR_GRACE_MS);\n\n    let params = WindowParamsBuilder::new()\n        .param(\"persistent\", \"true\")\n        .build();\n    let result = TrayMenuWindow.create_with_params(app_handle, params)?;\n\n    let win = app_handle\n        .get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)\n        .ok_or_else(|| anyhow::anyhow!(\"failed to get tray menu window\"))?;\n\n    if result.is_new {\n        setup_tray_menu_focus_handler(&win);\n    }\n\n    let _ = win.show();\n    let _ = win.set_focus();\n\n    Ok(())\n}\n\n/// Show the webview tray menu window near the given cursor position.\npub fn show_tray_menu_window(\n    app_handle: &AppHandle,\n    cursor: tauri::PhysicalPosition<f64>,\n) -> Result<()> {\n    use tauri::{Manager, PhysicalPosition};\n","sourceCodeStart":581,"sourceCodeEnd":617,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/resolve.rs#L581-L617","documentation":"create_debug_tray_menu_window creates the tray menu webview window via TrayMenuWindow.create_with_params and then immediately looks it up by label. If get_webview_window returns None after creation — the window was not registered under TRAY_MENU_WINDOW_LABEL — this error is raised.","triggerScenarios":"create_with_params reported success (or the ? on its result passed) but the label lookup fails: creation silently skipped registration, a label mismatch between builder and consts::TRAY_MENU_WINDOW_LABEL, or the window was closed concurrently.","commonSituations":"Refactors changing the window label in one place only; window auto-closing due to a crash during webview load; create_with_params returning Ok but not actually creating (already-exists handling); races with another thread closing the window.","solutions":["Verify the label used when building TrayMenuWindow matches crate::consts::TRAY_MENU_WINDOW_LABEL exactly","Check create_with_params' return value (is_new / errors) — handle non-new cases without expecting a fresh registration","Log window labels registered on the AppHandle when this fires to spot mismatches","Avoid closing/re-creating the tray window concurrently; serialize tray window creation"],"exampleFix":"// before\nlet win = app_handle\n    .get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)\n    .ok_or_else(|| anyhow::anyhow!(\"failed to get tray menu window\"))?;\n// after: surface result details on failure\nlet win = app_handle\n    .get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)\n    .ok_or_else(|| anyhow::anyhow!(\n        \"failed to get tray menu window (is_new={}, result={:?})\",\n        result.is_new, result\n    ))?;","handlingStrategy":"try-catch","validationCode":"if app_handle.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL).is_none()\n    && !can_create_tray_menu_window(app_handle) {\n    bail!(\"tray menu window cannot be created in current state\");\n}","typeGuard":null,"tryCatchPattern":"let win = match app_handle.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL) {\n    Some(w) => w,\n    None => {\n        log::error!(\"tray menu window missing after creation\");\n        return Err(anyhow!(\"tray menu window unavailable\"));\n    }\n};","preventionTips":["Keep the creation label and consts::TRAY_MENU_WINDOW_LABEL in sync (derive one from the other)","Check create_with_params' result fields before the lookup","Avoid concurrent close/recreate of the tray window; serialize via an actor or mutex"],"tags":["tauri","window","tray","webview"],"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"}