libnyanpasu/clash-nyanpasu · error · anyhow::Error
failed to get tray menu window
Error message
failed to get tray menu window
What it means
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.
Source
Thrown at backend/tauri/src/utils/resolve.rs:599
}
}
_ => {}
});
}
/// Create a persistent tray menu window for debugging.
pub fn create_debug_tray_menu_window(app_handle: &AppHandle) -> Result<()> {
TRAY_MENU_PERSISTENT.store(true, Ordering::Release);
ignore_tray_menu_blur_for(TRAY_MENU_SHOW_BLUR_GRACE_MS);
let params = WindowParamsBuilder::new()
.param("persistent", "true")
.build();
let result = TrayMenuWindow.create_with_params(app_handle, params)?;
let win = app_handle
.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)
.ok_or_else(|| anyhow::anyhow!("failed to get tray menu window"))?;
if result.is_new {
setup_tray_menu_focus_handler(&win);
}
let _ = win.show();
let _ = win.set_focus();
Ok(())
}
/// Show the webview tray menu window near the given cursor position.
pub fn show_tray_menu_window(
app_handle: &AppHandle,
cursor: tauri::PhysicalPosition<f64>,
) -> Result<()> {
use tauri::{Manager, PhysicalPosition};
View on GitHub (pinned to f7dbce2997)
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
Example fix
// before
let win = app_handle
.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)
.ok_or_else(|| anyhow::anyhow!("failed to get tray menu window"))?;
// after: surface result details on failure
let win = app_handle
.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL)
.ok_or_else(|| anyhow::anyhow!(
"failed to get tray menu window (is_new={}, result={:?})",
result.is_new, result
))?; Defensive patterns
Strategy: try-catch
Validate before calling
if app_handle.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL).is_none()
&& !can_create_tray_menu_window(app_handle) {
bail!("tray menu window cannot be created in current state");
} Try / catch
let win = match app_handle.get_webview_window(crate::consts::TRAY_MENU_WINDOW_LABEL) {
Some(w) => w,
None => {
log::error!("tray menu window missing after creation");
return Err(anyhow!("tray menu window unavailable"));
}
}; Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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 tray menu window after creation
- failed to get window
- tray not found
- update_systray unhandled error
- app_handle is not exist
AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08).
Data as JSON: /api/errors/8141e3604975117e.
Report an issue: GitHub.