geekorm_core/
error.rs

1//! Error Module for GeekORM
2
3/// Error type for the crate
4#[derive(Debug, thiserror::Error, Clone)]
5pub enum Error {
6    /// Database Connection Error
7    #[error("Connection Error: {0}")]
8    ConnectionError(String),
9    /// Database Schema Error
10    #[error("Schema Error: {0}")]
11    SchemaError(String),
12    /// Database Migration Error
13    #[cfg(feature = "migrations")]
14    #[error("{0}")]
15    MigrationError(#[from] MigrationError),
16
17    /// Query Builder Error
18    #[error("QueryBuilderError: {0} ({1})")]
19    QueryBuilderError(String, String),
20
21    /// Column Not Found
22    #[error("ColumnNotFound: Table({0}) {1}")]
23    ColumnNotFound(String, String),
24
25    /// Column Skipped
26    #[error("Column Skipped")]
27    ColumnSkipped,
28
29    /// No Rows was found in the database for the query
30    #[error("No Rows Found - Query: '{query}'")]
31    NoRowsFound {
32        /// Query
33        query: String,
34    },
35
36    /// Pagination Error
37    #[cfg(feature = "pagination")]
38    #[error("Pagination Error: {0}")]
39    PaginationError(String),
40
41    /// Not Implemented
42    #[error("Not Implemented")]
43    NotImplemented,
44
45    /// Error Hashing Password
46    #[error("Error Hashing Password: {0}")]
47    HashingError(String),
48
49    /// Serde Error
50    #[error("Serde Error: {0}")]
51    SerdeError(String),
52
53    /// Unknown Variant
54    #[error("Unknown Variant {0}")]
55    UnknownVariant(String),
56
57    /// Unknown / Generic Error
58    #[error("Unknown Error / Generic Error occurred")]
59    Unknown,
60
61    /// TOTP Error
62    #[cfg(feature = "two-factor-auth")]
63    #[error("TOTP Error: {0}")]
64    TotpError(String),
65    /// SystemTime Error
66    #[error("SystemTime Error: {0}")]
67    SystemTimeError(#[from] std::time::SystemTimeError),
68
69    /// IO Error
70    #[error("IO Error: {0}")]
71    IOError(String),
72
73    /// LibSQL Error
74    #[cfg(feature = "libsql")]
75    #[error(
76        "LibSQL Error: {error}\n -> {query}\nPlease report this error to the GeekORM developers"
77    )]
78    LibSQLError {
79        /// Error message
80        error: String,
81        /// Query
82        query: String,
83    },
84
85    /// RuSQLite Error
86    #[cfg(feature = "rusqlite")]
87    #[error("RuSQLite Error occurred: {0}")]
88    RuSQLiteError(String),
89
90    /// Query Syntax Error
91    #[error(
92        "Query Syntax Error: {error}\n -> {query}\nPlease report this error to the GeekORM developers"
93    )]
94    QuerySyntaxError {
95        /// Error message
96        error: String,
97        /// Query
98        query: String,
99    },
100}
101
102/// GeekORM Migration Error
103#[cfg(feature = "migrations")]
104#[derive(Debug, thiserror::Error, Clone)]
105pub enum MigrationError {
106    /// Missing Table (table name)
107    #[error("Missing Table `{0}`")]
108    MissingTable(String),
109    /// Missing Column (table name, column name)
110    #[error("Missing Column `{table}.{column}`")]
111    MissingColumn {
112        /// Table name
113        table: String,
114        /// Column name
115        column: String,
116    },
117    /// Column Type Mismatch (table name, column name, feature)
118    #[error("Column Type Mismatch `{table}.{column}`: {feature}")]
119    ColumnTypeMismatch {
120        /// Table name
121        table: String,
122        /// Column name
123        column: String,
124        /// Feature
125        feature: String,
126    },
127
128    /// New Table (table name)
129    #[error("New Table `{table}`")]
130    NewTable {
131        /// Table name
132        table: String,
133    },
134    /// New Column (table name, column name)
135    #[error("New Column `{table}.{column}`")]
136    NewColumn {
137        /// Table name
138        table: String,
139        /// Column name
140        column: String,
141    },
142
143    /// Upgrade Error (reason)
144    #[error("Upgrade Error: {0}")]
145    UpgradeError(String),
146    /// Missing Migration (migration name)
147    #[error("Missing Migration: {0}")]
148    MissingMigration(String),
149}
150
151impl From<std::io::Error> for Error {
152    fn from(e: std::io::Error) -> Self {
153        Self::IOError(e.to_string())
154    }
155}
156
157#[cfg(feature = "rusqlite")]
158impl From<::rusqlite::Error> for Error {
159    fn from(e: ::rusqlite::Error) -> Self {
160        Self::RuSQLiteError(e.to_string())
161    }
162}