Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/psqlpy/_internal/exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PyToRustValueMappingError(RustPSQLDriverPyBaseError):
So, if there are no parameters for the query, don't handle this error.
"""

class DBTransactionError(RustPSQLDriverPyBaseError):
class TransactionError(RustPSQLDriverPyBaseError):
"""Error if something goes wrong with `Transaction`.

It has verbose error message.
Expand All @@ -37,3 +37,6 @@ class UUIDValueConvertError(RustPSQLDriverPyBaseError):

class CursorError(RustPSQLDriverPyBaseError):
"""Error if something goes wrong with the cursor."""

class MacAddr6ConversionError(RustPSQLDriverPyBaseError):
"""Error if cannot convert MacAddr6 string value to rust type."""
7 changes: 4 additions & 3 deletions python/psqlpy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
CursorError,
DBPoolConfigurationError,
DBPoolError,
DBTransactionError,
MacAddr6ConversionError,
PyToRustValueMappingError,
RustPSQLDriverPyBaseError,
RustToPyValueMappingError,
TransactionError,
UUIDValueConvertError,
)

Expand All @@ -14,9 +15,9 @@
"DBPoolError",
"RustToPyValueMappingError",
"PyToRustValueMappingError",
"DBTransactionError",
"TransactionError",
"DBPoolConfigurationError",
"UUIDValueConvertError",
"CursorError",
"DBTransactionError",
"MacAddr6ConversionError",
]
4 changes: 2 additions & 2 deletions python/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.helpers import count_rows_in_test_table

from psqlpy import PSQLPool, QueryResult, Transaction
from psqlpy.exceptions import DBTransactionError, RustPSQLDriverPyBaseError
from psqlpy.exceptions import RustPSQLDriverPyBaseError, TransactionError

pytestmark = pytest.mark.anyio

Expand Down Expand Up @@ -57,7 +57,7 @@ async def test_connection_execute_many(
f"INSERT INTO {table_name} VALUES ($1, $2)",
insert_values,
)
except DBTransactionError:
except TransactionError:
assert not insert_values
else:
assert await count_rows_in_test_table(
Expand Down
10 changes: 5 additions & 5 deletions python/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.helpers import count_rows_in_test_table

from psqlpy import Cursor, IsolationLevel, PSQLPool, ReadVariant
from psqlpy.exceptions import DBTransactionError, RustPSQLDriverPyBaseError
from psqlpy.exceptions import RustPSQLDriverPyBaseError, TransactionError

pytestmark = pytest.mark.anyio

Expand Down Expand Up @@ -55,7 +55,7 @@ async def test_transaction_begin(
connection = await psql_pool.connection()
transaction = connection.transaction()

with pytest.raises(expected_exception=DBTransactionError):
with pytest.raises(expected_exception=TransactionError):
await transaction.execute(
f"SELECT * FROM {table_name}",
)
Expand Down Expand Up @@ -157,7 +157,7 @@ async def test_transaction_rollback(

await transaction.rollback()

with pytest.raises(expected_exception=DBTransactionError):
with pytest.raises(expected_exception=TransactionError):
await transaction.execute(
f"SELECT * FROM {table_name} WHERE name = $1",
parameters=[test_name],
Expand All @@ -184,7 +184,7 @@ async def test_transaction_release_savepoint(

await transaction.savepoint(sp_name_1)

with pytest.raises(expected_exception=DBTransactionError):
with pytest.raises(expected_exception=TransactionError):
await transaction.savepoint(sp_name_1)

await transaction.savepoint(sp_name_2)
Expand Down Expand Up @@ -227,7 +227,7 @@ async def test_transaction_execute_many(
f"INSERT INTO {table_name} VALUES ($1, $2)",
insert_values,
)
except DBTransactionError:
except TransactionError:
assert not insert_values
else:
assert await count_rows_in_test_table(
Expand Down
4 changes: 2 additions & 2 deletions src/driver/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl InnerCursor {
let db_transaction_arc = self.db_transaction.clone();

if self.closed {
return Err(RustPSQLDriverError::DBCursorError(
return Err(RustPSQLDriverError::DataBaseCursorError(
"Cursor is already closed".into(),
));
}
Expand Down Expand Up @@ -120,7 +120,7 @@ impl InnerCursor {
let db_transaction_arc = self.db_transaction.clone();

if !self.is_started {
return Err(RustPSQLDriverError::DBCursorError(
return Err(RustPSQLDriverError::DataBaseCursorError(
"Cursor is not opened, please call `start()`.".into(),
));
}
Expand Down
14 changes: 12 additions & 2 deletions src/exceptions/python_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ create_exception!(
);
create_exception!(
psqlpy.exceptions,
DBTransactionError,
TransactionError,
RustPSQLDriverPyBaseError
);
create_exception!(
Expand All @@ -33,6 +33,12 @@ create_exception!(
RustPSQLDriverPyBaseError
);

create_exception!(
psqlpy.exceptions,
MacAddr6ConversionError,
RustPSQLDriverPyBaseError
);

create_exception!(psqlpy.exceptions, CursorError, RustPSQLDriverPyBaseError);

#[allow(clippy::missing_errors_doc)]
Expand All @@ -50,7 +56,7 @@ pub fn python_exceptions_module(py: Python<'_>, pymod: &PyModule) -> PyResult<()
"PyToRustValueMappingError",
py.get_type::<PyToRustValueMappingError>(),
)?;
pymod.add("DBTransactionError", py.get_type::<DBTransactionError>())?;
pymod.add("TransactionError", py.get_type::<TransactionError>())?;
pymod.add(
"DBPoolConfigurationError",
py.get_type::<DBPoolConfigurationError>(),
Expand All @@ -60,5 +66,9 @@ pub fn python_exceptions_module(py: Python<'_>, pymod: &PyModule) -> PyResult<()
py.get_type::<UUIDValueConvertError>(),
)?;
pymod.add("CursorError", py.get_type::<CursorError>())?;
pymod.add(
"MacAddr6ConversionError",
py.get_type::<MacAddr6ConversionError>(),
)?;
Ok(())
}
10 changes: 5 additions & 5 deletions src/exceptions/rust_errors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use thiserror::Error;

use crate::exceptions::python_errors::{
DBPoolConfigurationError, DBPoolError, DBTransactionError, PyToRustValueMappingError,
RustPSQLDriverPyBaseError, RustToPyValueMappingError,
DBPoolConfigurationError, DBPoolError, PyToRustValueMappingError, RustPSQLDriverPyBaseError,
RustToPyValueMappingError, TransactionError,
};

use super::python_errors::{CursorError, UUIDValueConvertError};
Expand All @@ -22,7 +22,7 @@ pub enum RustPSQLDriverError {
#[error("Configuration database pool error: {0}")]
DataBasePoolConfigurationError(String),
#[error("Cursor error: {0}")]
DBCursorError(String),
DataBaseCursorError(String),

#[error("Python exception: {0}.")]
PyError(#[from] pyo3::PyErr),
Expand Down Expand Up @@ -57,13 +57,13 @@ impl From<RustPSQLDriverError> for pyo3::PyErr {
}
RustPSQLDriverError::DatabasePoolError(_) => DBPoolError::new_err((error_desc,)),
RustPSQLDriverError::DataBaseTransactionError(_) => {
DBTransactionError::new_err((error_desc,))
TransactionError::new_err((error_desc,))
}
RustPSQLDriverError::DataBasePoolConfigurationError(_) => {
DBPoolConfigurationError::new_err((error_desc,))
}
RustPSQLDriverError::UUIDConvertError(_) => UUIDValueConvertError::new_err(error_desc),
RustPSQLDriverError::DBCursorError(_) => CursorError::new_err(error_desc),
RustPSQLDriverError::DataBaseCursorError(_) => CursorError::new_err(error_desc),
}
}
}