ave_core/distribution/
error.rs1use thiserror::Error;
2
3use ave_actors::ActorError;
4use ave_common::identity::DigestIdentifier;
5
6#[derive(Debug, Error, Clone)]
7pub enum DistributorError {
8 #[error("governance is not authorized")]
9 GovernanceNotAuthorized,
10
11 #[error("we are not witness for this subject")]
12 NotWitness,
13
14 #[error(
15 "subject not found: we do not have the subject that we have been asked for"
16 )]
17 SubjectNotFound,
18
19 #[error("sender '{sender}' is not a member of governance")]
20 SenderNotMember { sender: String },
21
22 #[error("sender does not have access to the subject")]
23 SenderNoAccess,
24
25 #[error("missing governance_id for tracker subject {subject_id}")]
26 MissingGovernanceId { subject_id: DigestIdentifier },
27
28 #[error(
29 "missing governance_id in create event for tracker subject {subject_id}"
30 )]
31 MissingGovernanceIdInCreate { subject_id: DigestIdentifier },
32
33 #[error("updating subject, need to fetch first event")]
34 UpdatingSubject,
35
36 #[error(
37 "actual_sn ({actual_sn}) is greater than or equal to witness sn ({witness_sn})"
38 )]
39 ActualSnBiggerThanWitness { actual_sn: u64, witness_sn: u64 },
40
41 #[error("sender is not the expected one")]
42 UnexpectedSender,
43
44 #[error("events list is empty")]
45 EmptyEvents,
46
47 #[error("missing create event in create ledger for subject {subject_id}")]
48 MissingCreateEventInCreateLedger { subject_id: DigestIdentifier },
49
50 #[error(
51 "our governance version ({our_version}) is less than theirs ({their_version})"
52 )]
53 GovernanceVersionMismatch {
54 our_version: u64,
55 their_version: u64,
56 },
57
58 #[error("failed to get governance data: {details}")]
59 GetGovernanceFailed { details: String },
60
61 #[error("failed to up tracker: {details}")]
62 UpTrackerFailed { details: String },
63
64 #[error("failed to update subject ledger: {details}")]
65 UpdateLedgerFailed { details: String },
66}
67
68impl From<DistributorError> for ActorError {
69 fn from(error: DistributorError) -> Self {
70 match error {
71 DistributorError::GovernanceNotAuthorized
72 | DistributorError::NotWitness
73 | DistributorError::SubjectNotFound
74 | DistributorError::SenderNotMember { .. }
75 | DistributorError::SenderNoAccess
76 | DistributorError::UpdatingSubject
77 | DistributorError::ActualSnBiggerThanWitness { .. }
78 | DistributorError::UnexpectedSender
79 | DistributorError::EmptyEvents
80 | DistributorError::MissingCreateEventInCreateLedger { .. }
81 | DistributorError::GetGovernanceFailed { .. }
82 | DistributorError::GovernanceVersionMismatch { .. } => {
83 Self::Functional {
84 description: error.to_string(),
85 }
86 }
87 DistributorError::MissingGovernanceId { .. }
88 | DistributorError::MissingGovernanceIdInCreate { .. }
89 | DistributorError::UpTrackerFailed { .. }
90 | DistributorError::UpdateLedgerFailed { .. } => {
91 Self::FunctionalCritical {
92 description: error.to_string(),
93 }
94 }
95 }
96 }
97}