Skip to main content

appcore_sync_sqlite/
error.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: error.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: 2026/08/26 00:00:00 by dnettoRaw
7//    ##   ## ##   ##    U: 2026/08/26 00:00:00 by dnettoRaw
8//      ###########      S: 2.0.0
9// =============================================================================
10
11use appcore_sync::SyncError;
12use std::fmt;
13
14/// Result produced by the `SQLite` sync provider.
15pub type SqliteSyncResult<T> = Result<T, SqliteSyncError>;
16
17/// Typed provider error whose diagnostics never contain paths, SQL or payloads.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum SqliteSyncError {
20    /// Provider configuration violates a fixed bound.
21    InvalidConfiguration(&'static str),
22    /// The database path is not an owner-controlled regular-file location.
23    UnsafePath,
24    /// The persistent schema is removed, unversioned or newer than supported.
25    UpdateRequired,
26    /// `SQLite` rejected an internal operation.
27    DatabaseOperation,
28    /// Database integrity validation failed.
29    IntegrityFailed,
30    /// A provider capacity limit was reached.
31    CapacityExceeded(&'static str),
32    /// A stored provider record is structurally invalid.
33    CorruptRecord(&'static str),
34}
35
36impl SqliteSyncError {
37    pub(crate) fn database(_error: rusqlite::Error) -> Self {
38        Self::DatabaseOperation
39    }
40
41    pub(crate) fn sync(self) -> SyncError {
42        SyncError::ReplicationFailed(self.to_string())
43    }
44}
45
46impl fmt::Display for SqliteSyncError {
47    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match self {
49            Self::InvalidConfiguration(reason) => {
50                write!(formatter, "invalid SQLite sync configuration: {reason}")
51            }
52            Self::UnsafePath => formatter.write_str("SQLite sync path is unsafe"),
53            Self::UpdateRequired => formatter.write_str("NO MORE SUPPORTED PLEASE UPDATE"),
54            Self::DatabaseOperation => formatter.write_str("SQLite sync operation failed"),
55            Self::IntegrityFailed => formatter.write_str("SQLite sync integrity check failed"),
56            Self::CapacityExceeded(resource) => {
57                write!(formatter, "SQLite sync {resource} capacity exceeded")
58            }
59            Self::CorruptRecord(kind) => write!(formatter, "corrupt SQLite sync {kind} record"),
60        }
61    }
62}
63
64impl std::error::Error for SqliteSyncError {}