kaccy_reputation/
error.rs

1//! Reputation error types
2
3use rust_decimal::Decimal;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7pub enum ReputationError {
8    // Database errors
9    #[error("Database error: {0}")]
10    Database(#[from] sqlx::Error),
11
12    // Validation errors
13    #[error("Validation error: {0}")]
14    Validation(String),
15
16    #[error("Invalid rating: {0}")]
17    InvalidRating(String),
18
19    #[error("Invalid score delta: {delta}, max allowed: {max_allowed}")]
20    InvalidScoreDelta {
21        delta: Decimal,
22        max_allowed: Decimal,
23    },
24
25    #[error("Invalid state transition: from {from} to {to}")]
26    InvalidStateTransition { from: String, to: String },
27
28    // Not found errors
29    #[error("User not found: {0}")]
30    UserNotFound(String),
31
32    #[error("Commitment not found: {0}")]
33    CommitmentNotFound(String),
34
35    #[error("Token not found: {0}")]
36    TokenNotFound(String),
37
38    #[error("Dispute not found: {0}")]
39    DisputeNotFound(String),
40
41    #[error("SBT not found for user: {0}")]
42    SBTNotFound(String),
43
44    // Authorization errors
45    #[error("Unauthorized: {0}")]
46    Unauthorized(String),
47
48    #[error("Cannot rate own token")]
49    CannotRateOwnToken,
50
51    #[error("Insufficient balance to rate: required {required}, current {current}")]
52    InsufficientBalance { required: Decimal, current: Decimal },
53
54    #[error("Insufficient holding duration: required {required_hours}h, held for {held_hours}h")]
55    InsufficientHoldingDuration {
56        required_hours: i64,
57        held_hours: i64,
58    },
59
60    // Reputation errors
61    #[error("Circuit breaker triggered for user: {0}")]
62    CircuitBreakerTriggered(String),
63
64    #[error("Insufficient reputation: required {required}, current {current}")]
65    InsufficientReputation { required: Decimal, current: Decimal },
66
67    #[error("Cannot issue tokens: {0}")]
68    CannotIssueTokens(String),
69
70    // Commitment errors
71    #[error("Commitment already verified")]
72    CommitmentAlreadyVerified,
73
74    #[error("Commitment deadline expired")]
75    CommitmentDeadlineExpired,
76
77    #[error("Evidence required for commitment verification")]
78    EvidenceRequired,
79
80    // Dispute errors
81    #[error("Dispute already resolved")]
82    DisputeAlreadyResolved,
83
84    #[error("Voting period ended")]
85    VotingPeriodEnded,
86
87    #[error("Voting period not yet ended")]
88    VotingPeriodNotEnded,
89
90    #[error("User already voted on this dispute")]
91    AlreadyVoted,
92
93    #[error("Insufficient voting power: required {required}, current {current}")]
94    InsufficientVotingPower { required: Decimal, current: Decimal },
95
96    // SBT errors
97    #[error("SBT already minted for user: {0}")]
98    SBTAlreadyMinted(String),
99
100    #[error("SBT not yet minted for user: {0}")]
101    SBTNotMinted(String),
102}
103
104pub type Result<T> = std::result::Result<T, ReputationError>;