appcore_sync_sqlite/
error.rs1use appcore_sync::SyncError;
12use std::fmt;
13
14pub type SqliteSyncResult<T> = Result<T, SqliteSyncError>;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum SqliteSyncError {
20 InvalidConfiguration(&'static str),
22 UnsafePath,
24 UpdateRequired,
26 DatabaseOperation,
28 IntegrityFailed,
30 CapacityExceeded(&'static str),
32 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 {}