@@ -2,18 +2,62 @@ use thiserror::Error;
22use tokio:: task:: JoinError ;
33
44use crate :: exceptions:: python_errors:: {
5- DBPoolConfigurationError , DBPoolError , PyToRustValueMappingError , RustPSQLDriverPyBaseError ,
6- RustToPyValueMappingError , TransactionError ,
5+ DBPoolConfigurationError , DBPoolError , PyToRustValueMappingError , RustToPyValueMappingError ,
6+ TransactionError ,
77} ;
88
9- use super :: python_errors:: { CursorError , UUIDValueConvertError } ;
9+ use super :: python_errors:: {
10+ BaseConnectionError , BaseConnectionPoolError , BaseCursorError , BaseTransactionError ,
11+ ConnectionExecuteError , ConnectionPoolBuildError , ConnectionPoolExecuteError , CursorCloseError ,
12+ CursorError , CursorFetchError , CursorStartError , DriverError , MacAddrParseError ,
13+ RuntimeJoinError , TransactionBeginError , TransactionCommitError , TransactionExecuteError ,
14+ TransactionRollbackError , TransactionSavepointError , UUIDValueConvertError ,
15+ } ;
1016
1117pub type RustPSQLDriverPyResult < T > = Result < T , RustPSQLDriverError > ;
1218
1319#[ derive( Error , Debug ) ]
1420pub enum RustPSQLDriverError {
21+ // ConnectionPool errors
22+ #[ error( "Connection pool error: {0}." ) ]
23+ BaseConnectionPoolError ( String ) ,
24+ #[ error( "Connection pool build error: {0}." ) ]
25+ ConnectionPoolBuildError ( String ) ,
26+ #[ error( "Connection pool execute error: {0}." ) ]
27+ ConnectionPoolExecuteError ( String ) ,
28+
29+ // Connection Errors
30+ #[ error( "Connection error: {0}." ) ]
31+ BaseConnectionError ( String ) ,
32+ #[ error( "Connection execute error: {0}." ) ]
33+ ConnectionExecuteError ( String ) ,
34+
35+ // Transaction Errors
36+ #[ error( "Transaction error: {0}" ) ]
37+ BaseTransactionError ( String ) ,
38+ #[ error( "Transaction begin error: {0}" ) ]
39+ TransactionBeginError ( String ) ,
40+ #[ error( "Transaction commit error: {0}" ) ]
41+ TransactionCommitError ( String ) ,
42+ #[ error( "Transaction rollback error: {0}" ) ]
43+ TransactionRollbackError ( String ) ,
44+ #[ error( "Transaction savepoint error: {0}" ) ]
45+ TransactionSavepointError ( String ) ,
46+ #[ error( "Transaction execute error: {0}" ) ]
47+ TransactionExecuteError ( String ) ,
48+
49+ // Cursor Errors
50+ #[ error( "Cursor error: {0}" ) ]
51+ BaseCursorError ( String ) ,
52+ #[ error( "Cursor start error: {0}" ) ]
53+ CursorStartError ( String ) ,
54+ #[ error( "Cursor close error: {0}" ) ]
55+ CursorCloseError ( String ) ,
56+ #[ error( "Cursor fetch error: {0}" ) ]
57+ CursorFetchError ( String ) ,
58+
1559 #[ error( "Database pool error: {0}." ) ]
16- DatabasePoolError ( String ) ,
60+ ConnectionPoolError ( String ) ,
1761 #[ error( "Can't convert value from driver to python type: {0}" ) ]
1862 RustToPyValueConversionError ( String ) ,
1963 #[ error( "Can't convert value from python to rust type: {0}" ) ]
@@ -26,48 +70,89 @@ pub enum RustPSQLDriverError {
2670 DataBaseCursorError ( String ) ,
2771
2872 #[ error( "Python exception: {0}." ) ]
29- PyError ( #[ from] pyo3:: PyErr ) ,
73+ RustPyError ( #[ from] pyo3:: PyErr ) ,
3074 #[ error( "Database engine exception: {0}." ) ]
31- DBEngineError ( #[ from] deadpool_postgres:: tokio_postgres:: Error ) ,
75+ RustDriverError ( #[ from] deadpool_postgres:: tokio_postgres:: Error ) ,
3276 #[ error( "Database engine pool exception: {0}" ) ]
33- DBEnginePoolError ( #[ from] deadpool_postgres:: PoolError ) ,
77+ RustConnectionPoolError ( #[ from] deadpool_postgres:: PoolError ) ,
3478 #[ error( "Database engine build failed: {0}" ) ]
35- DBEngineBuildError ( #[ from] deadpool_postgres:: BuildError ) ,
79+ RustDriverBuildError ( #[ from] deadpool_postgres:: BuildError ) ,
3680 #[ error( "Value convert has failed: {0}" ) ]
37- UUIDConvertError ( #[ from] uuid:: Error ) ,
81+ RustUUIDConvertError ( #[ from] uuid:: Error ) ,
3882 #[ error( "Cannot convert provided string to MacAddr6" ) ]
39- MacAddr6ConversionError ( #[ from] macaddr:: ParseError ) ,
83+ RustMacAddrConversionError ( #[ from] macaddr:: ParseError ) ,
4084 #[ error( "Cannot execute future in Rust: {0}" ) ]
41- RuntimeJoinError ( #[ from] JoinError ) ,
85+ RustRuntimeJoinError ( #[ from] JoinError ) ,
4286}
4387
4488impl From < RustPSQLDriverError > for pyo3:: PyErr {
4589 fn from ( error : RustPSQLDriverError ) -> Self {
4690 let error_desc = error. to_string ( ) ;
4791 match error {
48- RustPSQLDriverError :: PyError ( err) => err,
49- RustPSQLDriverError :: DBEngineError ( _)
50- | RustPSQLDriverError :: DBEnginePoolError ( _)
51- | RustPSQLDriverError :: MacAddr6ConversionError ( _ )
52- | RustPSQLDriverError :: DBEngineBuildError ( _ )
53- | RustPSQLDriverError :: RuntimeJoinError ( _) => {
54- RustPSQLDriverPyBaseError :: new_err ( ( error_desc, ) )
92+ RustPSQLDriverError :: RustPyError ( err) => err,
93+ RustPSQLDriverError :: RustDriverError ( _) => DriverError :: new_err ( ( error_desc , ) ) ,
94+ RustPSQLDriverError :: RustMacAddrConversionError ( _) => {
95+ MacAddrParseError :: new_err ( ( error_desc , ) )
96+ }
97+ RustPSQLDriverError :: RustRuntimeJoinError ( _) => {
98+ RuntimeJoinError :: new_err ( ( error_desc, ) )
5599 }
56100 RustPSQLDriverError :: RustToPyValueConversionError ( _) => {
57101 RustToPyValueMappingError :: new_err ( ( error_desc, ) )
58102 }
59103 RustPSQLDriverError :: PyToRustValueConversionError ( _) => {
60104 PyToRustValueMappingError :: new_err ( ( error_desc, ) )
61105 }
62- RustPSQLDriverError :: DatabasePoolError ( _) => DBPoolError :: new_err ( ( error_desc, ) ) ,
106+ RustPSQLDriverError :: ConnectionPoolError ( _) => DBPoolError :: new_err ( ( error_desc, ) ) ,
63107 RustPSQLDriverError :: DataBaseTransactionError ( _) => {
64108 TransactionError :: new_err ( ( error_desc, ) )
65109 }
66110 RustPSQLDriverError :: DataBasePoolConfigurationError ( _) => {
67111 DBPoolConfigurationError :: new_err ( ( error_desc, ) )
68112 }
69- RustPSQLDriverError :: UUIDConvertError ( _) => UUIDValueConvertError :: new_err ( error_desc) ,
113+ RustPSQLDriverError :: RustUUIDConvertError ( _) => {
114+ UUIDValueConvertError :: new_err ( error_desc)
115+ }
70116 RustPSQLDriverError :: DataBaseCursorError ( _) => CursorError :: new_err ( error_desc) ,
117+ RustPSQLDriverError :: BaseConnectionPoolError ( _)
118+ | RustPSQLDriverError :: RustConnectionPoolError ( _) => {
119+ BaseConnectionPoolError :: new_err ( ( error_desc, ) )
120+ }
121+ RustPSQLDriverError :: ConnectionPoolBuildError ( _)
122+ | RustPSQLDriverError :: RustDriverBuildError ( _) => {
123+ ConnectionPoolBuildError :: new_err ( ( error_desc, ) )
124+ }
125+ RustPSQLDriverError :: ConnectionPoolExecuteError ( _) => {
126+ ConnectionPoolExecuteError :: new_err ( ( error_desc, ) )
127+ }
128+ RustPSQLDriverError :: BaseConnectionError ( _) => {
129+ BaseConnectionError :: new_err ( ( error_desc, ) )
130+ }
131+ RustPSQLDriverError :: ConnectionExecuteError ( _) => {
132+ ConnectionExecuteError :: new_err ( ( error_desc, ) )
133+ }
134+ RustPSQLDriverError :: BaseTransactionError ( _) => {
135+ BaseTransactionError :: new_err ( ( error_desc, ) )
136+ }
137+ RustPSQLDriverError :: TransactionBeginError ( _) => {
138+ TransactionBeginError :: new_err ( ( error_desc, ) )
139+ }
140+ RustPSQLDriverError :: TransactionCommitError ( _) => {
141+ TransactionCommitError :: new_err ( ( error_desc, ) )
142+ }
143+ RustPSQLDriverError :: TransactionRollbackError ( _) => {
144+ TransactionRollbackError :: new_err ( ( error_desc, ) )
145+ }
146+ RustPSQLDriverError :: TransactionSavepointError ( _) => {
147+ TransactionSavepointError :: new_err ( ( error_desc, ) )
148+ }
149+ RustPSQLDriverError :: TransactionExecuteError ( _) => {
150+ TransactionExecuteError :: new_err ( ( error_desc, ) )
151+ }
152+ RustPSQLDriverError :: BaseCursorError ( _) => BaseCursorError :: new_err ( ( error_desc, ) ) ,
153+ RustPSQLDriverError :: CursorStartError ( _) => CursorStartError :: new_err ( ( error_desc, ) ) ,
154+ RustPSQLDriverError :: CursorCloseError ( _) => CursorCloseError :: new_err ( ( error_desc, ) ) ,
155+ RustPSQLDriverError :: CursorFetchError ( _) => CursorFetchError :: new_err ( ( error_desc, ) ) ,
71156 }
72157 }
73158}
0 commit comments