diff --git a/quaint/src/connector/transaction.rs b/quaint/src/connector/transaction.rs index a861748b2b54..682b745c0da2 100644 --- a/quaint/src/connector/transaction.rs +++ b/quaint/src/connector/transaction.rs @@ -177,9 +177,7 @@ impl Transaction for DefaultTransaction<'_> { let depth_val = self.depth.load(Ordering::Relaxed); if depth_val == 0 { - panic!( - "No savepoint to release in transaction, make sure to call create_savepoint before release_savepoint" - ); + return Err(Error::builder(ErrorKind::NoSavepointToRelease(depth_val)).build()); } // Perform the asynchronous operation without holding the lock diff --git a/quaint/src/error/mod.rs b/quaint/src/error/mod.rs index 661eb4d344ff..22232fbbcb1a 100644 --- a/quaint/src/error/mod.rs +++ b/quaint/src/error/mod.rs @@ -241,6 +241,9 @@ pub enum ErrorKind { #[error("External error id#{}", _0)] ExternalError(i32), + + #[error("No savepoint to release in transaction for depth '{}', make sure to call create_savepoint before release_savepoint", _0)] + NoSavepointToRelease(u32), } #[cfg(not(target_arch = "wasm32"))] diff --git a/query-engine/connectors/query-connector/src/error.rs b/query-engine/connectors/query-connector/src/error.rs index 6e6e37b1d16e..b571c1a7c419 100644 --- a/query-engine/connectors/query-connector/src/error.rs +++ b/query-engine/connectors/query-connector/src/error.rs @@ -282,6 +282,9 @@ pub enum ErrorKind { #[error("External connector error")] ExternalError(i32), + #[error("No savepoint to release in transaction for depth '{}', make sure to call create_savepoint before release_savepoint", _0)] + NoSavepointToRelease(u32), + #[error("Invalid driver adapter: {0}")] InvalidDriverAdapter(String), diff --git a/query-engine/connectors/sql-query-connector/src/error.rs b/query-engine/connectors/sql-query-connector/src/error.rs index f3e76d84fd9e..03b690f2ca9c 100644 --- a/query-engine/connectors/sql-query-connector/src/error.rs +++ b/query-engine/connectors/sql-query-connector/src/error.rs @@ -209,6 +209,9 @@ pub enum SqlError { #[error("External connector error")] ExternalError(i32), + #[error("No savepoint to release in transaction for depth '{}', make sure to call create_savepoint before release_savepoint", _0)] + NoSavepointToRelease(u32), + #[error("Too many DB connections opened")] TooManyConnections(Box), } @@ -296,6 +299,9 @@ impl SqlError { SqlError::InvalidIsolationLevel(msg) => ConnectorError::from_kind(ErrorKind::InternalConversionError(msg)), SqlError::ExternalError(error_id) => ConnectorError::from_kind(ErrorKind::ExternalError(error_id)), SqlError::TooManyConnections(e) => ConnectorError::from_kind(ErrorKind::TooManyConnections(e)), + SqlError::NoSavepointToRelease(depth_val) => { + ConnectorError::from_kind(ErrorKind::NoSavepointToRelease(depth_val)) + } } } } @@ -350,6 +356,7 @@ impl From for SqlError { QuaintKind::TransactionWriteConflict => Self::TransactionWriteConflict, QuaintKind::RollbackWithoutBegin => Self::RollbackWithoutBegin, QuaintKind::ExternalError(error_id) => Self::ExternalError(error_id), + QuaintKind::NoSavepointToRelease(depth_val) => Self::NoSavepointToRelease(depth_val), QuaintKind::TooManyConnections(e) => Self::TooManyConnections(e), e @ QuaintKind::UnsupportedColumnType { .. } => SqlError::ConversionError(e.into()), e @ QuaintKind::TransactionAlreadyClosed(_) => SqlError::TransactionAlreadyClosed(format!("{e}")),