Skip to main content

ave_core/distribution/
error.rs

1use 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("actual_sn ({actual_sn}) is bigger than witness sn ({witness_sn})")]
37    ActualSnBiggerThanWitness { actual_sn: u64, witness_sn: u64 },
38
39    #[error("sender is not the expected one")]
40    UnexpectedSender,
41
42    #[error("events list is empty")]
43    EmptyEvents,
44
45    #[error(
46        "our governance version ({our_version}) is less than theirs ({their_version})"
47    )]
48    GovernanceVersionMismatch {
49        our_version: u64,
50        their_version: u64,
51    },
52
53    #[error("failed to get governance data: {details}")]
54    GetGovernanceFailed { details: String },
55
56    #[error("failed to up tracker: {details}")]
57    UpTrackerFailed { details: String },
58
59    #[error("failed to update subject ledger: {details}")]
60    UpdateLedgerFailed { details: String },
61}
62
63impl From<DistributorError> for ActorError {
64    fn from(error: DistributorError) -> Self {
65        match error {
66            DistributorError::GovernanceNotAuthorized
67            | DistributorError::NotWitness
68            | DistributorError::SubjectNotFound
69            | DistributorError::SenderNotMember { .. }
70            | DistributorError::SenderNoAccess
71            | DistributorError::UpdatingSubject
72            | DistributorError::ActualSnBiggerThanWitness { .. }
73            | DistributorError::UnexpectedSender
74            | DistributorError::EmptyEvents
75            | DistributorError::GetGovernanceFailed { .. }
76            | DistributorError::GovernanceVersionMismatch { .. } => {
77                Self::Functional {
78                    description: error.to_string(),
79                }
80            }
81            DistributorError::MissingGovernanceId { .. }
82            | DistributorError::MissingGovernanceIdInCreate { .. }
83            | DistributorError::UpTrackerFailed { .. }
84            | DistributorError::UpdateLedgerFailed { .. } => {
85                Self::FunctionalCritical {
86                    description: error.to_string(),
87                }
88            }
89        }
90    }
91}