use std::fmt;
use crate::{
action,
common::{self, error::FatalError},
interaction, transaction,
};
#[derive(Debug, thiserror::Error)]
pub enum InitError {
#[error("{0}")]
Fatal(#[from] FatalError),
}
#[derive(Debug, thiserror::Error)]
pub enum StageInteractionError {
#[error("{0}")]
Interaction(#[from] interaction::Error),
#[error("{0}")]
Fatal(#[from] FatalError),
}
#[derive(Debug, thiserror::Error)]
pub enum RevertInteractionError {
#[error("{0}")]
InvalidInteractionPending(#[from] InvalidInteractionPendingError),
#[error("{0}")]
Fatal(#[from] FatalError),
}
#[derive(Debug, thiserror::Error)]
pub enum ApplyInteractionError {
#[error("{0}")]
InvalidInteractionPending(#[from] InvalidInteractionPendingError),
#[error("{0}")]
Fatal(#[from] FatalError),
}
#[derive(Debug, thiserror::Error)]
pub enum SignalError {
#[error("{0}")]
Fatal(#[from] FatalError),
}
#[derive(Debug, thiserror::Error)]
#[error(
"The pending interaction {pending_interaction} does not exist, or has already been applied or reverted"
)]
pub struct InvalidInteractionPendingError {
pub pending_interaction: interaction::Pending,
}
impl InvalidInteractionPendingError {
pub(crate) fn new(pending_interaction: interaction::Pending) -> Self {
Self {
pending_interaction,
}
}
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum TransactionConfirmationError {
#[error("{0}")]
Action(#[from] action::Error),
#[error("{0}")]
Mismatch(#[from] transaction::id::MismatchError),
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum TransactionOutOfOrderError {
#[error("Expected pending id {}, received {actual}", expected.as_ref().map(|tp| tp as &dyn fmt::Display).unwrap_or(&"None"))]
WrongPendingId {
expected: Option<interaction::Pending>,
actual: interaction::Pending,
},
#[error("Expected confirmed id {expected}, received {actual}")]
WrongConfirmdId {
expected: transaction::Id,
actual: transaction::Id,
},
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum ConfirmPendingError {
#[error("{0}")]
Action(#[from] common::error::RecoverableError<action::Error>),
#[error("{0}")]
OutOfOrder(#[from] TransactionOutOfOrderError),
}