Skip to main content

rusticx_core/
error.rs

1use thiserror::Error;
2
3/// All errors that Rusticx operations can produce.
4///
5/// Every fallible method in Rusticx returns `Result<T, RusticxError>`.
6/// Match on specific variants to handle connection failures, missing records,
7/// schema problems, or type mismatches independently.
8#[derive(Debug, Error)]
9pub enum RusticxError {
10    #[error("Connection error: {0}")]
11    Connection(String),
12
13    #[error("Query error: {0}")]
14    Query(String),
15
16    #[error("Serialization error: {0}")]
17    Serialization(String),
18
19    #[error("Deserialization error: {0}")]
20    Deserialization(String),
21
22    #[error("Record not found: {0}")]
23    NotFound(String),
24
25    #[error("Duplicate key: {0}")]
26    DuplicateKey(String),
27
28    #[error("Migration error: {0}")]
29    Migration(String),
30
31    #[error("Schema error: {0}")]
32    Schema(String),
33
34    #[error("Transaction error: {0}")]
35    Transaction(String),
36
37    #[error("Pool error: {0}")]
38    Pool(String),
39
40    #[error("Unsupported operation: {0}")]
41    Unsupported(String),
42
43    #[error("Configuration error: {0}")]
44    Configuration(String),
45
46    #[error("Type mismatch: expected {expected}, got {got}")]
47    TypeMismatch { expected: String, got: String },
48
49    #[error("Unknown error: {0}")]
50    Unknown(String),
51}
52
53pub type Result<T> = std::result::Result<T, RusticxError>;