Skip to main content

tenzro_token/
error.rs

1//! Error types for the token module
2
3use thiserror::Error;
4
5/// Result type for token operations
6pub type Result<T> = std::result::Result<T, TokenError>;
7
8/// Errors that can occur in token operations
9#[derive(Debug, Error)]
10pub enum TokenError {
11    /// Insufficient balance for the operation
12    #[error("Insufficient balance: required {required}, available {available}")]
13    InsufficientBalance { required: u128, available: u128 },
14
15    /// Insufficient stake for the operation
16    #[error("Insufficient stake: required {required}, available {available}")]
17    InsufficientStake { required: u128, available: u128 },
18
19    /// Stake is locked and cannot be withdrawn
20    #[error("Stake is locked until {unlock_time}")]
21    StakeLocked { unlock_time: i64 },
22
23    /// Invalid amount (e.g., zero or negative)
24    #[error("Invalid amount: {0}")]
25    InvalidAmount(String),
26
27    /// Proposal not found
28    #[error("Proposal not found: {proposal_id}")]
29    ProposalNotFound { proposal_id: String },
30
31    /// Voting period has closed
32    #[error("Voting has closed for proposal: {proposal_id}")]
33    VotingClosed { proposal_id: String },
34
35    /// User has already voted on this proposal
36    #[error("Already voted on proposal: {proposal_id}")]
37    AlreadyVoted { proposal_id: String },
38
39    /// Quorum not met for proposal
40    #[error("Quorum not met for proposal: {proposal_id}")]
41    QuorumNotMet { proposal_id: String },
42
43    /// Unauthorized operation
44    #[error("Unauthorized: {reason}")]
45    Unauthorized { reason: String },
46
47    /// Treasury operation error
48    #[error("Treasury error: {message}")]
49    TreasuryError { message: String },
50
51    /// Storage operation error
52    #[error("Storage error: {0}")]
53    StorageError(String),
54
55    /// Invalid configuration
56    #[error("Invalid configuration: {0}")]
57    InvalidConfig(String),
58
59    /// Arithmetic overflow
60    #[error("Arithmetic overflow in {operation}")]
61    ArithmeticOverflow { operation: String },
62
63    /// Invalid address
64    #[error("Invalid address")]
65    InvalidAddress,
66
67    /// Asset not found
68    #[error("Asset not found: {asset_id}")]
69    AssetNotFound { asset_id: String },
70
71    /// Stake not found
72    #[error("Stake not found for address: {address}")]
73    StakeNotFound { address: String },
74
75    /// Minimum stake not met
76    #[error("Minimum stake not met: required {required}, provided {provided}")]
77    MinimumStakeNotMet { required: u128, provided: u128 },
78
79    /// Invalid proposal type
80    #[error("Invalid proposal type")]
81    InvalidProposalType,
82
83    /// Proposal already executed
84    #[error("Proposal already executed: {proposal_id}")]
85    ProposalAlreadyExecuted { proposal_id: String },
86
87    /// Proposal executor returned an error during apply
88    #[error("Proposal execution failed for {proposal_id}: {reason}")]
89    ProposalExecutionFailed { proposal_id: String, reason: String },
90
91    /// Invalid voting power
92    #[error("Invalid voting power: must have staked TNZO to vote")]
93    InvalidVotingPower,
94
95    /// Generic invalid-parameter error (used by bond/insurance flows).
96    #[error("Invalid parameter: {0}")]
97    InvalidParameter(String),
98
99    /// Generic not-found error (used by bond/insurance flows).
100    #[error("Not found: {0}")]
101    NotFound(String),
102}
103
104impl From<tenzro_storage::StorageError> for TokenError {
105    fn from(err: tenzro_storage::StorageError) -> Self {
106        TokenError::StorageError(err.to_string())
107    }
108}