Skip to main content

reddb_server/runtime/
transaction_state.rs

1//! Native compatibility path and error classification for shared transaction state.
2use reddb_engine::transaction::state::SavepointError;
3pub(crate) use reddb_engine::transaction::state::TransactionState;
4
5impl From<SavepointError> for crate::api::RedDBError {
6    fn from(error: SavepointError) -> Self {
7        Self::Internal(error.to_string())
8    }
9}
10
11#[cfg(test)]
12mod tests {
13    use super::*;
14    use crate::api::RedDBError;
15    use crate::storage::transaction::IsolationLevel;
16
17    #[test]
18    fn missing_savepoints_preserve_native_error_classification() {
19        let state = TransactionState::new();
20        state.begin(1, IsolationLevel::SnapshotIsolation);
21        for error in [
22            state.release_savepoint(1, "missing").err(),
23            state.rollback_to_savepoint(1, "missing").err(),
24        ] {
25            let native: RedDBError = error.expect("missing savepoint fails").into();
26            assert!(
27                matches!(native, RedDBError::Internal(message) if message == "savepoint missing does not exist")
28            );
29        }
30    }
31}