{"record":{"id":"d3e000965fec3326","repo":"Zackriya-Solutions/meetily","slug":"failed-to-emit-first-launch-detected-event","errorCode":null,"errorMessage":"Failed to emit first-launch-detected event","messagePattern":"Failed to emit first-launch-detected event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"frontend/src-tauri/src/database/setup.rs","lineNumber":24,"sourceCode":"\n/// Initialize database on app startup\n/// Handles first launch detection and conditional initialization\npub async fn initialize_database_on_startup(app: &AppHandle) -> Result<(), String> {\n    // Check if this is the first launch (no database exists yet)\n    let is_first_launch = DatabaseManager::is_first_launch(app)\n        .await\n        .map_err(|e| format!(\"Failed to check first launch status: {}\", e))?;\n\n    if is_first_launch {\n        info!(\"First launch detected - will notify window when ready\");\n\n        // Delay event emission to ensure window is ready and React listeners are registered\n        let app_handle = app.clone();\n        tauri::async_runtime::spawn(async move {\n            tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;\n            app_handle\n                .emit(\"first-launch-detected\", ())\n                .expect(\"Failed to emit first-launch-detected event\");\n            info!(\"Emitted first-launch-detected after delay\");\n        });\n    } else {\n        // Normal flow - initialize database immediately\n        let db_manager = DatabaseManager::new_from_app_handle(app)\n            .await\n            .map_err(|e| format!(\"Failed to initialize database manager: {}\", e))?;\n\n        app.manage(AppState { db_manager });\n        info!(\"Database initialized successfully\");\n    }\n\n    Ok(())\n}\n","sourceCodeStart":6,"sourceCodeEnd":39,"githubUrl":"https://github.com/Zackriya-Solutions/meetily/blob/0281737d87d26352fb0adc78c8c0975f691b23d1/frontend/src-tauri/src/database/setup.rs#L6-L39","documentation":"Emitter::emit returns tauri::Result and fails when the event cannot be delivered — typically when no live webview window exists or the event channel is unavailable (window creation failed, app tearing down). Here it runs in a spawned task 500ms after setup, so a slow/failed window load or an immediate quit turns the first-launch notification into an async-task panic.","triggerScenarios":"First-launch flow where the main window is still initializing, failed to create, or was closed before the 500ms delay elapsed; emitting during RunEvent::Exit teardown; headless test runs without a real webview.","commonSituations":"Slow machines where webview startup exceeds the hard-coded 500ms, GPU/webview-runtime issues on Windows, users quitting the app within the first second.","solutions":["Replace .expect with `if let Err(e) = ... { log::warn!(...) }` — a missed UI notification must never crash","Invert the flow: let the frontend query first-launch status when React mounts, instead of a timed push","Guard emission by checking that at least one webview window exists (app.webview_windows().is_empty()) before emitting"],"exampleFix":"// before\napp_handle.emit(\"first-launch-detected\", ())\n    .expect(\"Failed to emit first-launch-detected event\");\n\n// after\nif let Err(e) = app_handle.emit(\"first-launch-detected\", ()) {\n    log::warn!(\"first-launch event not delivered: {e}\");\n}","handlingStrategy":"try-catch","validationCode":"if !app_handle.webview_windows().is_empty() {\n    let _ = app_handle.emit(\"first-launch-detected\", ());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = app_handle.emit(\"first-launch-detected\", ()) {\n    log::warn!(\"first-launch event not delivered: {e}\");\n}","preventionTips":["Never expect() on event emission — the webview may not be ready or may be gone","Prefer pull over push: let the frontend query first-launch state after mount","Use window-ready events (e.g. on page load) instead of hard-coded sleep delays"],"tags":["rust","tauri","events","ipc","first-launch"],"backgroundTag":"tauri-event-emit-failed","analyzedSha":"0281737d87d26352fb0adc78c8c0975f691b23d1","analyzedAt":"2026-08-16T20:57:52.567Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}