fix: treat missing db file as error in manual backup to prevent false success toast

backup_database_file() returning Ok(None) was silently resolved as null
on the frontend, bypassing try/catch and showing a success toast without
actually creating a backup file. Now None is converted to an explicit
Err so the frontend correctly displays an error toast.
This commit is contained in:
Jason
2026-02-26 21:53:59 +08:00
parent 54876612b3
commit 3590df68b8
2 changed files with 22 additions and 0 deletions

View File

@@ -123,6 +123,24 @@ pub async fn open_zip_file_dialog<R: tauri::Runtime>(
// ─── Database backup management ─────────────────────────────
/// Manually create a database backup
#[tauri::command]
pub async fn create_db_backup(state: State<'_, AppState>) -> Result<String, String> {
let db = state.db.clone();
tauri::async_runtime::spawn_blocking(move || match db.backup_database_file()? {
Some(path) => Ok(path
.file_name()
.map(|f| f.to_string_lossy().into_owned())
.unwrap_or_default()),
None => Err(AppError::Config(
"Database file not found, backup skipped".to_string(),
)),
})
.await
.map_err(|e| format!("Backup failed: {e}"))?
.map_err(|e: AppError| e.to_string())
}
/// List all database backup files
#[tauri::command]
pub fn list_db_backups() -> Result<Vec<BackupEntry>, String> {