Skip to main content

dpp_domain/domain/transfer/
error.rs

1//! [`TransferError`] — errors from transfer-of-responsibility operations.
2
3use super::status::TransferStatus;
4
5/// Errors specific to transfer-of-responsibility operations.
6#[derive(Debug, Clone, PartialEq)]
7#[non_exhaustive]
8pub enum TransferError {
9    /// The `from_operator` on the transfer record doesn't match the
10    /// current responsible operator on the chain.
11    OperatorMismatch { expected: String, got: String },
12    /// A transfer is already pending for this passport.
13    TransferAlreadyPending,
14    /// The transfer record is not in a state that allows this operation.
15    InvalidState {
16        current: TransferStatus,
17        action: String,
18    },
19}
20
21impl std::fmt::Display for TransferError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            TransferError::OperatorMismatch { expected, got } => {
25                write!(f, "operator mismatch: expected {expected}, got {got}")
26            }
27            TransferError::TransferAlreadyPending => {
28                write!(f, "a transfer is already pending for this passport")
29            }
30            TransferError::InvalidState { current, action } => {
31                write!(f, "cannot {action}: transfer is in {current:?} state")
32            }
33        }
34    }
35}
36
37impl std::error::Error for TransferError {}