leptos_helios/data_sources/
errors.rs

1//! Data source connection errors
2//!
3//! This module provides comprehensive error handling for data source connections,
4//! including database connectivity, query execution, and schema introspection errors.
5
6// use std::time::Duration; // Currently unused
7
8/// Data source connection errors
9#[derive(Debug, thiserror::Error)]
10pub enum DataSourceError {
11    #[error("Connection failed: {0}")]
12    ConnectionFailed(String),
13
14    #[error("Query execution failed: {0}")]
15    QueryFailed(String),
16
17    #[error("Schema introspection failed: {0}")]
18    SchemaFailed(String),
19
20    #[error("Unsupported operation: {0}")]
21    UnsupportedOperation(String),
22
23    #[error("Authentication failed: {0}")]
24    AuthenticationFailed(String),
25
26    #[error("Invalid configuration: {0}")]
27    InvalidConfiguration(String),
28
29    #[error("Timeout error: {0}")]
30    Timeout(String),
31
32    #[error("Data type conversion failed: {0}")]
33    DataTypeConversion(String),
34
35    #[error("Transaction failed: {0}")]
36    TransactionFailed(String),
37
38    #[error("Connection pool exhausted: {0}")]
39    PoolExhausted(String),
40}
41
42impl DataSourceError {
43    /// Create a new connection failed error
44    pub fn connection_failed(message: impl Into<String>) -> Self {
45        Self::ConnectionFailed(message.into())
46    }
47
48    /// Create a new query execution failed error
49    pub fn query_failed(message: impl Into<String>) -> Self {
50        Self::QueryFailed(message.into())
51    }
52
53    /// Create a new schema introspection failed error
54    pub fn schema_failed(message: impl Into<String>) -> Self {
55        Self::SchemaFailed(message.into())
56    }
57
58    /// Create a new unsupported operation error
59    pub fn unsupported_operation(message: impl Into<String>) -> Self {
60        Self::UnsupportedOperation(message.into())
61    }
62
63    /// Create a new authentication failed error
64    pub fn authentication_failed(message: impl Into<String>) -> Self {
65        Self::AuthenticationFailed(message.into())
66    }
67
68    /// Create a new invalid configuration error
69    pub fn invalid_configuration(message: impl Into<String>) -> Self {
70        Self::InvalidConfiguration(message.into())
71    }
72
73    /// Create a new timeout error
74    pub fn timeout(message: impl Into<String>) -> Self {
75        Self::Timeout(message.into())
76    }
77
78    /// Create a new data type conversion error
79    pub fn data_type_conversion(message: impl Into<String>) -> Self {
80        Self::DataTypeConversion(message.into())
81    }
82
83    /// Create a new transaction failed error
84    pub fn transaction_failed(message: impl Into<String>) -> Self {
85        Self::TransactionFailed(message.into())
86    }
87
88    /// Create a new connection pool exhausted error
89    pub fn pool_exhausted(message: impl Into<String>) -> Self {
90        Self::PoolExhausted(message.into())
91    }
92
93    /// Check if this is a connection error
94    pub fn is_connection_error(&self) -> bool {
95        matches!(
96            self,
97            DataSourceError::ConnectionFailed(_) | DataSourceError::AuthenticationFailed(_)
98        )
99    }
100
101    /// Check if this is a query error
102    pub fn is_query_error(&self) -> bool {
103        matches!(
104            self,
105            DataSourceError::QueryFailed(_) | DataSourceError::UnsupportedOperation(_)
106        )
107    }
108
109    /// Check if this is a configuration error
110    pub fn is_configuration_error(&self) -> bool {
111        matches!(self, DataSourceError::InvalidConfiguration(_))
112    }
113
114    /// Check if this is a timeout error
115    pub fn is_timeout_error(&self) -> bool {
116        matches!(self, DataSourceError::Timeout(_))
117    }
118
119    /// Check if this is a transaction error
120    pub fn is_transaction_error(&self) -> bool {
121        matches!(self, DataSourceError::TransactionFailed(_))
122    }
123
124    /// Check if this is a pool error
125    pub fn is_pool_error(&self) -> bool {
126        matches!(self, DataSourceError::PoolExhausted(_))
127    }
128}