#[derive(thiserror::Error)]
pub enum TransactionError<C: std::error::Error, P: std::error::Error> {
#[error("transaction is read-only")]
ReadOnly,
#[error("transaction conflict, please retry")]
Conflict,
#[error("transaction has been discarded, please create a new one")]
Discard,
#[error("transaction is too large")]
LargeTxn,
#[error("transaction manager error: {0}")]
Pwm(P),
#[error("conflict manager error: {0}")]
Cm(C),
}
impl<C: std::error::Error, P: std::error::Error> core::fmt::Debug for TransactionError<C, P> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ReadOnly => write!(f, "ReadOnly"),
Self::Conflict => write!(f, "Conflict"),
Self::Discard => write!(f, "Discard"),
Self::LargeTxn => write!(f, "LargeTxn"),
Self::Pwm(e) => write!(f, "Pwm({:?})", e),
Self::Cm(e) => write!(f, "Cm({:?})", e),
}
}
}
impl<C: std::error::Error, P: std::error::Error> TransactionError<C, P> {
#[inline]
pub const fn conflict(err: C) -> Self {
Self::Cm(err)
}
#[inline]
pub const fn pending(err: P) -> Self {
Self::Pwm(err)
}
}
pub enum WtmError<C: std::error::Error, P: std::error::Error, E: std::error::Error> {
Transaction(TransactionError<C, P>),
Commit(E),
}
impl<C: std::error::Error, P: std::error::Error, E: std::error::Error> core::fmt::Debug
for WtmError<C, P, E>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Transaction(e) => write!(f, "Transaction({:?})", e),
Self::Commit(e) => write!(f, "Commit({:?})", e),
}
}
}
impl<C: std::error::Error, P: std::error::Error, E: std::error::Error> core::fmt::Display
for WtmError<C, P, E>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Transaction(e) => write!(f, "transaction error: {e}"),
Self::Commit(e) => write!(f, "commit error: {e}"),
}
}
}
impl<C: std::error::Error, P: std::error::Error, E: std::error::Error> std::error::Error
for WtmError<C, P, E>
{
}
impl<C: std::error::Error, P: std::error::Error, E: std::error::Error> From<TransactionError<C, P>>
for WtmError<C, P, E>
{
#[inline]
fn from(err: TransactionError<C, P>) -> Self {
Self::Transaction(err)
}
}
impl<C: std::error::Error, P: std::error::Error, E: std::error::Error> WtmError<C, P, E> {
#[inline]
pub const fn transaction(err: TransactionError<C, P>) -> Self {
Self::Transaction(err)
}
#[inline]
pub const fn commit(err: E) -> Self {
Self::Commit(err)
}
}