{"record":{"id":"c4641b315636acc3","repo":"Zackriya-Solutions/meetily","slug":"failed-to-initialize-database","errorCode":null,"errorMessage":"Failed to initialize database","messagePattern":"Failed to initialize database","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"frontend/src-tauri/src/lib.rs","lineNumber":500,"sourceCode":"                    }\n                }\n            });\n\n            // Trigger system audio permission request on startup (similar to microphone permission)\n            // #[cfg(target_os = \"macos\")]\n            // {\n            //     tauri::async_runtime::spawn(async {\n            //         if let Err(e) = audio::permissions::trigger_system_audio_permission() {\n            //             log::warn!(\"Failed to trigger system audio permission: {}\", e);\n            //         }\n            //     });\n            // }\n\n            // Initialize database (handles first launch detection and conditional setup)\n            tauri::async_runtime::block_on(async {\n                database::setup::initialize_database_on_startup(&_app.handle()).await\n            })\n            .expect(\"Failed to initialize database\");\n\n            // Initialize bundled templates directory for dynamic template discovery\n            log::info!(\"Initializing bundled templates directory...\");\n            if let Ok(resource_path) = _app.handle().path().resource_dir() {\n                let templates_dir = resource_path.join(\"templates\");\n                log::info!(\"Setting bundled templates directory to: {:?}\", templates_dir);\n                summary::templates::set_bundled_templates_dir(templates_dir);\n            } else {\n                log::warn!(\"Failed to resolve resource directory for templates\");\n            }\n\n            Ok(())\n        })\n        .on_window_event(|window, event| {\n            if let tauri::WindowEvent::CloseRequested { api, .. } = event {\n                if window.label() == \"main\" {\n                    api.prevent_close();\n                    if let Err(e) = window.hide() {","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/Zackriya-Solutions/meetily/blob/0281737d87d26352fb0adc78c8c0975f691b23d1/frontend/src-tauri/src/lib.rs#L482-L518","documentation":"Startup initialization is wrapped in block_on(...).expect: any failure inside initialize_database_on_startup — first-launch detection (app_data_dir), creating the sqlite pool, running migrations, or legacy db copy — panics during Tauri setup and aborts launch. Typical underlying causes: corrupted meeting_minutes.sqlite, database locked by another instance, read-only app-data dir, disk full, sqlx migration mismatch.","triggerScenarios":"Starting the app with a corrupt or half-written sqlite file (previous crash mid-write), launching a second instance racing on the same database file, permissions changed on the app data directory, or running an older build against a newer schema.","commonSituations":"Force-quit during a meeting save, cloud-synced home folders locking the sqlite file, antivirus holding the db, users downgrading app versions.","solutions":["Replace expect with error propagation: log the underlying error and show a user-facing dialog with a retry/quit choice","If the db is corrupt: close the app, move meeting_minutes.sqlite aside, relaunch to let it recreate (accepts data loss of old meetings)","Enforce single-instance (Tauri single-instance plugin) to avoid locked-db races","Keep WAL checkpointing on exit (already present) and test startup with a full disk / read-only dir"],"exampleFix":"// before\ntauri::async_runtime::block_on(async {\n    database::setup::initialize_database_on_startup(&_app.handle()).await\n}).expect(\"Failed to initialize database\");\n\n// after\nif let Err(e) = tauri::async_runtime::block_on(async {\n    database::setup::initialize_database_on_startup(&_app.handle()).await\n}) {\n    log::error!(\"database init failed: {e:#}\");\n    std::process::exit(1); // or show a native error dialog\n}","handlingStrategy":"fallback","validationCode":"// preflight before startup init\nlet dir = app.path().app_data_dir()?;\nif dir.read_file_test_failed() { /* rename aside */ }","typeGuard":null,"tryCatchPattern":"if let Err(e) = tauri::async_runtime::block_on(async {\n    database::setup::initialize_database_on_startup(&app.handle()).await\n}) {\n    log::error!(\"database init failed: {e:#}\");\n    // show dialog, offer reset: move meeting_minutes.sqlite aside and retry\n}","preventionTips":["Never .expect() on startup database init; propagate to a user-visible dialog","Enforce single-instance so two app copies cannot lock the sqlite file","Keep backups of meeting_minutes.sqlite before upgrades; test startup with corrupt/locked db files"],"tags":["rust","tauri","sqlite","sqlx","startup","database"],"backgroundTag":"database-initialization-failed","analyzedSha":"0281737d87d26352fb0adc78c8c0975f691b23d1","analyzedAt":"2026-08-16T20:57:52.567Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}