Skip to content

Commit

Permalink
fix: return error instead of panicking in release_savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianBuzzo committed Jan 13, 2025
1 parent c454efc commit a8542f2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions quaint/src/connector/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions quaint/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
3 changes: 3 additions & 0 deletions query-engine/connectors/query-connector/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
7 changes: 7 additions & 0 deletions query-engine/connectors/sql-query-connector/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error + Send + Sync>),
}
Expand Down Expand Up @@ -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))
}
}
}
}
Expand Down Expand Up @@ -350,6 +356,7 @@ impl From<quaint::error::Error> 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}")),
Expand Down

0 comments on commit a8542f2

Please sign in to comment.