xdl_database/
error.rs

1//! Database error types
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum DatabaseError {
7    #[error("Connection error: {0}")]
8    ConnectionError(String),
9
10    #[error("Query execution error: {0}")]
11    QueryError(String),
12
13    #[error("Data conversion error: {0}")]
14    ConversionError(String),
15
16    #[error("Not connected to database")]
17    NotConnected,
18
19    #[error("Unsupported database type: {0}")]
20    UnsupportedDatabase(String),
21
22    #[error("Invalid connection string: {0}")]
23    InvalidConnectionString(String),
24
25    #[error("Database-specific error: {0}")]
26    DatabaseSpecific(String),
27
28    #[cfg(feature = "postgres-support")]
29    #[error("PostgreSQL error: {0}")]
30    PostgresError(#[from] tokio_postgres::Error),
31
32    #[cfg(feature = "mysql-support")]
33    #[error("MySQL error: {0}")]
34    MySQLError(String),
35
36    #[cfg(feature = "duckdb-support")]
37    #[error("DuckDB error: {0}")]
38    DuckDBError(String),
39
40    #[cfg(feature = "sqlite-support")]
41    #[error("SQLite error: {0}")]
42    SQLiteError(String),
43
44    #[cfg(feature = "odbc-support")]
45    #[error("ODBC error: {0}")]
46    ODBCError(String),
47
48    #[cfg(feature = "redis-support")]
49    #[error("Redis error: {0}")]
50    RedisError(#[from] redis::RedisError),
51
52    #[error("IO error: {0}")]
53    IoError(#[from] std::io::Error),
54
55    #[error("Other error: {0}")]
56    Other(String),
57}
58
59impl DatabaseError {
60    pub fn connection_error(msg: impl Into<String>) -> Self {
61        Self::ConnectionError(msg.into())
62    }
63
64    pub fn query_error(msg: impl Into<String>) -> Self {
65        Self::QueryError(msg.into())
66    }
67
68    pub fn conversion_error(msg: impl Into<String>) -> Self {
69        Self::ConversionError(msg.into())
70    }
71}
72
73pub type DatabaseResult<T> = Result<T, DatabaseError>;