leptos_helios/data_sources/
errors.rs1#[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 pub fn connection_failed(message: impl Into<String>) -> Self {
45 Self::ConnectionFailed(message.into())
46 }
47
48 pub fn query_failed(message: impl Into<String>) -> Self {
50 Self::QueryFailed(message.into())
51 }
52
53 pub fn schema_failed(message: impl Into<String>) -> Self {
55 Self::SchemaFailed(message.into())
56 }
57
58 pub fn unsupported_operation(message: impl Into<String>) -> Self {
60 Self::UnsupportedOperation(message.into())
61 }
62
63 pub fn authentication_failed(message: impl Into<String>) -> Self {
65 Self::AuthenticationFailed(message.into())
66 }
67
68 pub fn invalid_configuration(message: impl Into<String>) -> Self {
70 Self::InvalidConfiguration(message.into())
71 }
72
73 pub fn timeout(message: impl Into<String>) -> Self {
75 Self::Timeout(message.into())
76 }
77
78 pub fn data_type_conversion(message: impl Into<String>) -> Self {
80 Self::DataTypeConversion(message.into())
81 }
82
83 pub fn transaction_failed(message: impl Into<String>) -> Self {
85 Self::TransactionFailed(message.into())
86 }
87
88 pub fn pool_exhausted(message: impl Into<String>) -> Self {
90 Self::PoolExhausted(message.into())
91 }
92
93 pub fn is_connection_error(&self) -> bool {
95 matches!(
96 self,
97 DataSourceError::ConnectionFailed(_) | DataSourceError::AuthenticationFailed(_)
98 )
99 }
100
101 pub fn is_query_error(&self) -> bool {
103 matches!(
104 self,
105 DataSourceError::QueryFailed(_) | DataSourceError::UnsupportedOperation(_)
106 )
107 }
108
109 pub fn is_configuration_error(&self) -> bool {
111 matches!(self, DataSourceError::InvalidConfiguration(_))
112 }
113
114 pub fn is_timeout_error(&self) -> bool {
116 matches!(self, DataSourceError::Timeout(_))
117 }
118
119 pub fn is_transaction_error(&self) -> bool {
121 matches!(self, DataSourceError::TransactionFailed(_))
122 }
123
124 pub fn is_pool_error(&self) -> bool {
126 matches!(self, DataSourceError::PoolExhausted(_))
127 }
128}