BREAKING CHANGE(core): replace the TypeScript database engine with a Rust-backed embedded server and bridge
This commit is contained in:
35
rust/crates/rustdb-txn/src/error.rs
Normal file
35
rust/crates/rustdb-txn/src/error.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use thiserror::Error;
|
||||
|
||||
/// Errors that can occur during transaction or session operations.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum TransactionError {
|
||||
#[error("not found: {0}")]
|
||||
NotFound(String),
|
||||
|
||||
#[error("transaction already active for session: {0}")]
|
||||
AlreadyActive(String),
|
||||
|
||||
#[error("write conflict detected (code 112): {0}")]
|
||||
WriteConflict(String),
|
||||
|
||||
#[error("session expired: {0}")]
|
||||
SessionExpired(String),
|
||||
|
||||
#[error("invalid transaction state: {0}")]
|
||||
InvalidState(String),
|
||||
}
|
||||
|
||||
impl TransactionError {
|
||||
/// Returns the error code.
|
||||
pub fn code(&self) -> i32 {
|
||||
match self {
|
||||
TransactionError::NotFound(_) => 251,
|
||||
TransactionError::AlreadyActive(_) => 256,
|
||||
TransactionError::WriteConflict(_) => 112,
|
||||
TransactionError::SessionExpired(_) => 6100,
|
||||
TransactionError::InvalidState(_) => 263,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type TransactionResult<T> = Result<T, TransactionError>;
|
||||
Reference in New Issue
Block a user