1use std::fmt;
6
7pub type SdkResult<T> = std::result::Result<T, SdkError>;
9
10#[derive(Debug)]
12pub enum SdkError {
13 DatabaseNotFound(String),
15 DatabaseAlreadyExists(String),
17 TableNotFound(String),
19 TableAlreadyExists(String),
21 DocumentNotFound(String),
23 InvalidQuery(String),
25 IoError(std::io::Error),
27 SerializationError(String),
29 ConstraintViolation(String),
31 TransactionError(String),
33 DatabaseClosed,
35 SecurityError(String),
37 BackupError(String),
39 Internal(String),
41}
42
43impl fmt::Display for SdkError {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 match self {
46 SdkError::DatabaseNotFound(p) => write!(f, "Database not found: {}", p),
47 SdkError::DatabaseAlreadyExists(p) => write!(f, "Database already exists: {}", p),
48 SdkError::TableNotFound(t) => write!(f, "Table not found: {}", t),
49 SdkError::TableAlreadyExists(t) => write!(f, "Table already exists: {}", t),
50 SdkError::DocumentNotFound(id) => write!(f, "Document not found: {}", id),
51 SdkError::InvalidQuery(q) => write!(f, "Invalid query: {}", q),
52 SdkError::IoError(e) => write!(f, "I/O error: {}", e),
53 SdkError::SerializationError(e) => write!(f, "Serialization error: {}", e),
54 SdkError::ConstraintViolation(c) => write!(f, "Constraint violation: {}", c),
55 SdkError::TransactionError(e) => write!(f, "Transaction error: {}", e),
56 SdkError::DatabaseClosed => write!(f, "Database is closed"),
57 SdkError::SecurityError(e) => write!(f, "Security error: {}", e),
58 SdkError::BackupError(e) => write!(f, "Backup error: {}", e),
59 SdkError::Internal(e) => write!(f, "Internal error: {}", e),
60 }
61 }
62}
63
64impl std::error::Error for SdkError {}
65
66impl From<std::io::Error> for SdkError {
67 fn from(e: std::io::Error) -> Self {
68 SdkError::IoError(e)
69 }
70}
71
72impl From<String> for SdkError {
73 fn from(e: String) -> Self {
74 SdkError::Internal(e)
75 }
76}
77
78impl From<serde_json::Error> for SdkError {
79 fn from(e: serde_json::Error) -> Self {
80 SdkError::SerializationError(e.to_string())
81 }
82}