mirror of
https://github.com/nyakang/nyaterm.git
synced 2026-09-22 16:01:31 +00:00
- Introduced a new action for resolving cloud sync conflicts by recovering the current remote snapshot. - Updated the SyncBackupHistoryPanel and SyncBackupTab components to handle remote inconsistency scenarios, providing appropriate user feedback and actions. - Added a utility function to determine if a remote conflict is inconsistent, improving conflict detection logic. - Enhanced the CloudSyncManager to manage remote snapshot resolutions, including handling legacy snapshots and ensuring consistency during sync operations. - Implemented new error handling for cloud sync operations, improving robustness and user experience.
97 lines
2.5 KiB
Rust
97 lines
2.5 KiB
Rust
//! Unified error type for Tauri commands.
|
|
//!
|
|
//! Provides `AppError` and `AppResult` for consistent error handling across the app.
|
|
|
|
use serde::Serialize;
|
|
|
|
/// Unified error type for all Tauri commands.
|
|
///
|
|
/// Implements `Serialize` so Tauri can pass the error message to the frontend.
|
|
/// Uses `thiserror` for ergonomic `From` conversions and `Display` formatting.
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum AppError {
|
|
#[error("SSH error: {0}")]
|
|
Ssh(#[from] russh::Error),
|
|
|
|
#[error("SSH key error: {0}")]
|
|
SshKey(#[from] russh::keys::Error),
|
|
|
|
#[error("IO error: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
|
|
#[error("JSON error: {0}")]
|
|
Json(#[from] serde_json::Error),
|
|
|
|
#[error("{0}")]
|
|
SessionNotFound(String),
|
|
|
|
#[error("{0}")]
|
|
Auth(String),
|
|
|
|
#[error("{0}")]
|
|
Config(String),
|
|
|
|
#[error("{0}")]
|
|
Storage(String),
|
|
|
|
#[error("{0}")]
|
|
Channel(String),
|
|
|
|
#[error("{0}")]
|
|
Cancelled(String),
|
|
|
|
#[error("SFTP error: {0}")]
|
|
Sftp(#[from] russh_sftp::client::error::Error),
|
|
|
|
#[error("Crypto error: {0}")]
|
|
Crypto(String),
|
|
|
|
#[error("{0}")]
|
|
CloudSync(#[from] CloudSyncError),
|
|
|
|
#[error("Translation error: {0}")]
|
|
Translation(String),
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
|
|
pub enum CloudSyncError {
|
|
#[error(
|
|
"Remote sync metadata is inconsistent: latest points to {revision} but the referenced snapshot is missing."
|
|
)]
|
|
SnapshotMissing { revision: String },
|
|
|
|
#[error(
|
|
"Remote sync snapshot revision mismatch: latest points to {pointer_revision} but snapshot contains {snapshot_revision}."
|
|
)]
|
|
RevisionMismatch {
|
|
pointer_revision: String,
|
|
snapshot_revision: String,
|
|
},
|
|
|
|
#[error("Remote sync snapshot hash mismatch: expected {expected} but got {actual}.")]
|
|
HashMismatch { expected: String, actual: String },
|
|
|
|
#[error(
|
|
"Remote sync was updated by another device: expected {expected_revision:?} but found {actual_revision:?}."
|
|
)]
|
|
ConcurrentUpdate {
|
|
expected_revision: Option<String>,
|
|
actual_revision: Option<String>,
|
|
},
|
|
|
|
#[error("Remote sync snapshot {revision} is corrupted.")]
|
|
CorruptedSnapshot { revision: String },
|
|
}
|
|
|
|
impl Serialize for AppError {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: serde::Serializer,
|
|
{
|
|
serializer.serialize_str(&self.to_string())
|
|
}
|
|
}
|
|
|
|
/// Convenience alias for `Result<T, AppError>`.
|
|
pub type AppResult<T> = Result<T, AppError>;
|