Skip to content

Commit c45253b

Browse files
authored
Merge pull request #41 from qaspen-python/feature/rewrite_exceptions
Rewrite all exceptions to more readable ones
2 parents 149d6c1 + d524b5d commit c45253b

File tree

5 files changed

+20
-42
lines changed

5 files changed

+20
-42
lines changed

python/psqlpy/_internal/exceptions.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ class ConnectionPoolConfigurationError(BaseConnectionPoolError):
1313
class ConnectionPoolExecuteError(BaseConnectionPoolError):
1414
"""Error in connection pool execution."""
1515

16-
class DBPoolConfigurationError(RustPSQLDriverPyBaseError):
17-
"""Error if configuration of the database pool is unacceptable."""
18-
1916
class BaseConnectionError(RustPSQLDriverPyBaseError):
2017
"""Base error for Connection errors."""
2118

@@ -55,8 +52,8 @@ class CursorFetchError(BaseCursorError):
5552
class UUIDValueConvertError(RustPSQLDriverPyBaseError):
5653
"""Error if it's impossible to convert py string UUID into rust UUID."""
5754

58-
class MacAddr6ConversionError(RustPSQLDriverPyBaseError):
59-
"""Error if cannot convert MacAddr6 string value to rust type."""
55+
class MacAddrConversionError(RustPSQLDriverPyBaseError):
56+
"""Error if cannot convert MacAddr string value to rust type."""
6057

6158
class RustToPyValueMappingError(RustPSQLDriverPyBaseError):
6259
"""Error if it is not possible to covert rust type to python.

python/psqlpy/exceptions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
CursorCloseError,
1111
CursorFetchError,
1212
CursorStartError,
13-
DBPoolConfigurationError,
14-
MacAddr6ConversionError,
13+
MacAddrConversionError,
1514
PyToRustValueMappingError,
1615
RustPSQLDriverPyBaseError,
1716
RustToPyValueMappingError,
@@ -43,7 +42,6 @@
4342
"RustPSQLDriverPyBaseError",
4443
"RustToPyValueMappingError",
4544
"PyToRustValueMappingError",
46-
"DBPoolConfigurationError",
4745
"UUIDValueConvertError",
48-
"MacAddr6ConversionError",
46+
"MacAddrConversionError",
4947
]

python/tests/test_connection_pool.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
TargetSessionAttrs,
1010
connect,
1111
)
12-
from psqlpy.exceptions import DBPoolConfigurationError, RustPSQLDriverPyBaseError
12+
from psqlpy.exceptions import (
13+
ConnectionPoolConfigurationError,
14+
RustPSQLDriverPyBaseError,
15+
)
1316

1417
pytestmark = pytest.mark.anyio
1518

@@ -94,22 +97,22 @@ async def test_pool_conn_recycling_method(
9497

9598

9699
async def test_build_pool_failure() -> None:
97-
with pytest.raises(expected_exception=DBPoolConfigurationError):
100+
with pytest.raises(expected_exception=ConnectionPoolConfigurationError):
98101
ConnectionPool(
99102
dsn="postgres://postgres:postgres@localhost:5432/psqlpy_test",
100103
connect_timeout_nanosec=12,
101104
)
102-
with pytest.raises(expected_exception=DBPoolConfigurationError):
105+
with pytest.raises(expected_exception=ConnectionPoolConfigurationError):
103106
ConnectionPool(
104107
dsn="postgres://postgres:postgres@localhost:5432/psqlpy_test",
105108
connect_timeout_nanosec=12,
106109
)
107-
with pytest.raises(expected_exception=DBPoolConfigurationError):
110+
with pytest.raises(expected_exception=ConnectionPoolConfigurationError):
108111
ConnectionPool(
109112
dsn="postgres://postgres:postgres@localhost:5432/psqlpy_test",
110113
keepalives_idle_nanosec=12,
111114
)
112-
with pytest.raises(expected_exception=DBPoolConfigurationError):
115+
with pytest.raises(expected_exception=ConnectionPoolConfigurationError):
113116
ConnectionPool(
114117
dsn="postgres://postgres:postgres@localhost:5432/psqlpy_test",
115118
keepalives_interval_nanosec=12,

src/exceptions/python_errors.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ create_exception!(
105105
PyToRustValueMappingError,
106106
RustPSQLDriverPyBaseError
107107
);
108-
create_exception!(
109-
psqlpy.exceptions,
110-
DBPoolConfigurationError,
111-
RustPSQLDriverPyBaseError
112-
);
113108

114109
create_exception!(
115110
psqlpy.exceptions,
@@ -123,12 +118,6 @@ create_exception!(
123118
RustPSQLDriverPyBaseError
124119
);
125120

126-
create_exception!(
127-
psqlpy.exceptions,
128-
RustRuntimeJoinError,
129-
RustPSQLDriverPyBaseError
130-
);
131-
132121
#[allow(clippy::missing_errors_doc)]
133122
pub fn python_exceptions_module(py: Python<'_>, pymod: &Bound<'_, PyModule>) -> PyResult<()> {
134123
pymod.add(
@@ -200,20 +189,12 @@ pub fn python_exceptions_module(py: Python<'_>, pymod: &Bound<'_, PyModule>) ->
200189
"PyToRustValueMappingError",
201190
py.get_type_bound::<PyToRustValueMappingError>(),
202191
)?;
203-
pymod.add(
204-
"DBPoolConfigurationError",
205-
py.get_type_bound::<DBPoolConfigurationError>(),
206-
)?;
207192
pymod.add(
208193
"UUIDValueConvertError",
209194
py.get_type_bound::<UUIDValueConvertError>(),
210195
)?;
211196
pymod.add(
212-
"MacAddr6ConversionError",
213-
py.get_type_bound::<MacAddrConversionError>(),
214-
)?;
215-
pymod.add(
216-
"RustRuntimeJoinError",
197+
"MacAddrConversionError",
217198
py.get_type_bound::<MacAddrConversionError>(),
218199
)?;
219200
Ok(())

src/exceptions/rust_errors.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use thiserror::Error;
22
use tokio::task::JoinError;
33

4-
use crate::exceptions::python_errors::{
5-
DBPoolConfigurationError, PyToRustValueMappingError, RustToPyValueMappingError,
6-
};
4+
use crate::exceptions::python_errors::{PyToRustValueMappingError, RustToPyValueMappingError};
75

86
use super::python_errors::{
97
BaseConnectionError, BaseConnectionPoolError, BaseCursorError, BaseTransactionError,
10-
ConnectionExecuteError, ConnectionPoolBuildError, ConnectionPoolExecuteError, CursorCloseError,
11-
CursorFetchError, CursorStartError, DriverError, MacAddrParseError, RuntimeJoinError,
12-
TransactionBeginError, TransactionCommitError, TransactionExecuteError,
13-
TransactionRollbackError, TransactionSavepointError, UUIDValueConvertError,
8+
ConnectionExecuteError, ConnectionPoolBuildError, ConnectionPoolConfigurationError,
9+
ConnectionPoolExecuteError, CursorCloseError, CursorFetchError, CursorStartError, DriverError,
10+
MacAddrParseError, RuntimeJoinError, TransactionBeginError, TransactionCommitError,
11+
TransactionExecuteError, TransactionRollbackError, TransactionSavepointError,
12+
UUIDValueConvertError,
1413
};
1514

1615
pub type RustPSQLDriverPyResult<T> = Result<T, RustPSQLDriverError>;
@@ -97,7 +96,7 @@ impl From<RustPSQLDriverError> for pyo3::PyErr {
9796
PyToRustValueMappingError::new_err((error_desc,))
9897
}
9998
RustPSQLDriverError::ConnectionPoolConfigurationError(_) => {
100-
DBPoolConfigurationError::new_err((error_desc,))
99+
ConnectionPoolConfigurationError::new_err((error_desc,))
101100
}
102101
RustPSQLDriverError::RustUUIDConvertError(_) => {
103102
UUIDValueConvertError::new_err(error_desc)

0 commit comments

Comments
 (0)