1use thiserror::Error;
7
8#[derive(Debug, Error)]
10pub enum CsafError {
11 #[error("Storage error: {0}")]
13 Storage(String),
14
15 #[error("Database error: {0}")]
17 Database(#[from] rusqlite::Error),
18
19 #[error("Serialization error: {0}")]
21 Serialization(#[from] serde_json::Error),
22
23 #[error("Validation failed: {0}")]
25 Validation(String),
26
27 #[error("I/O error: {0}")]
29 Io(#[from] std::io::Error),
30
31 #[error("Configuration error: {0}")]
33 Config(String),
34
35 #[error("Document not found: {0}")]
37 NotFound(String),
38
39 #[error("Document already exists: {0}")]
41 Duplicate(String),
42
43 #[error("Import error: {0}")]
45 Import(String),
46
47 #[error("Export error: {0}")]
49 Export(String),
50}
51
52impl From<redb::Error> for CsafError {
53 fn from(e: redb::Error) -> Self {
54 Self::Storage(e.to_string())
55 }
56}
57
58impl From<redb::DatabaseError> for CsafError {
59 fn from(e: redb::DatabaseError) -> Self {
60 Self::Storage(e.to_string())
61 }
62}
63
64impl From<redb::TableError> for CsafError {
65 fn from(e: redb::TableError) -> Self {
66 Self::Storage(e.to_string())
67 }
68}
69
70impl From<redb::TransactionError> for CsafError {
71 fn from(e: redb::TransactionError) -> Self {
72 Self::Storage(e.to_string())
73 }
74}
75
76impl From<redb::CommitError> for CsafError {
77 fn from(e: redb::CommitError) -> Self {
78 Self::Storage(e.to_string())
79 }
80}
81
82impl From<redb::StorageError> for CsafError {
83 fn from(e: redb::StorageError) -> Self {
84 Self::Storage(e.to_string())
85 }
86}
87
88pub type Result<T> = std::result::Result<T, CsafError>;