Skip to main content

ave_core/request/
error.rs

1use ave_actors::ActorError;
2use ave_common::identity::DigestIdentifier;
3use thiserror::Error;
4
5use crate::{
6    governance::error::GovernanceError,
7    model::error::{LedgerError, ProtocolsError},
8};
9
10#[derive(Debug, Error, Clone)]
11pub enum RequestHandlerError {
12    /// Helpers (hash algorithm, network sender) are not initialized.
13    #[error("helpers are not initialized")]
14    HelpersNotInitialized,
15
16    #[error("the payload cannot be deserialized as a governance event")]
17    GovFactInvalidEvent,
18
19    #[error("governance fact events cannot define viewpoints")]
20    GovFactViewpointsNotAllowed,
21
22    #[error("invalid tracker fact viewpoints: {0}")]
23    InvalidTrackerFactViewpoints(String),
24
25    #[error(
26        "tracker subject '{0}' cannot emit events because the local ledger is not full"
27    )]
28    TrackerLedgerNotFull(String),
29
30    /// Attempted to mark an approval as obsolete.
31    #[error("a user cannot mark a request approval as obsolete")]
32    ObsoleteApproval,
33
34    /// Approval actor not found for a subject.
35    #[error(
36        "no approval found for subject '{0}', node likely no longer has approver role"
37    )]
38    ApprovalNotFound(String),
39
40    /// Failed to change approval state.
41    #[error("failed to change approval state")]
42    ApprovalChangeFailed,
43
44    /// Failed to get approval state.
45    #[error("failed to get approval state")]
46    ApprovalGetFailed,
47
48    /// Not the owner of the subject.
49    #[error("not the owner of subject '{0}'")]
50    NotOwner(String),
51
52    /// There is a pending new_owner on the subject.
53    #[error("subject '{0}' has a pending new owner")]
54    PendingNewOwner(String),
55
56    /// The signer is the owner but should not be (Confirm/Reject).
57    #[error("signer is the owner of subject '{0}', cannot confirm/reject")]
58    IsOwner(String),
59
60    /// The signer is not the new owner (Confirm/Reject).
61    #[error("signer is not the new owner of subject '{0}'")]
62    NotNewOwner(String),
63
64    /// No new owner pending (Confirm/Reject).
65    #[error("no new owner pending for subject '{0}'")]
66    NoNewOwnerPending(String),
67
68    /// Subject name validation failed.
69    #[error("subject name must be between 1 and 100 characters")]
70    InvalidName,
71
72    /// Subject description validation failed.
73    #[error("subject description must be between 1 and 200 characters")]
74    InvalidDescription,
75
76    /// Invalid schema_id in request.
77    #[error("invalid schema_id in request")]
78    InvalidSchemaId,
79
80    /// Governance creation must have empty governance_id.
81    #[error("governance creation must have empty governance_id")]
82    GovernanceIdMustBeEmpty,
83
84    /// Governance creation must have empty namespace.
85    #[error("governance creation must have empty namespace")]
86    NamespaceMustBeEmpty,
87
88    /// Non-governance creation must have a governance_id.
89    #[error("non-governance creation must have a governance_id")]
90    GovernanceIdRequired,
91
92    /// Transfer event must have a new_owner.
93    #[error("transfer event must have a non-empty new_owner")]
94    TransferNewOwnerEmpty,
95
96    /// Confirm event name_old_owner is empty.
97    #[error(
98        "governance confirm event name_old_owner cannot be empty if present"
99    )]
100    ConfirmNameOldOwnerEmpty,
101
102    /// Confirm event for tracker should not have name_old_owner.
103    #[error("tracker confirm event must not have name_old_owner")]
104    ConfirmTrackerNameOldOwner,
105
106    /// SubjectData not found.
107    #[error("subject data not found for subject '{0}'")]
108    SubjectDataNotFound(String),
109
110    /// Subject is not active.
111    #[error("subject '{0}' is not active")]
112    SubjectNotActive(String),
113
114    /// Creation events cannot be queued.
115    #[error("creation events cannot be queued")]
116    CreationNotQueued,
117
118    /// Failed to compute request_id hash.
119    #[error("failed to compute request_id: {0}")]
120    RequestIdHash(String),
121
122    /// Failed to compute subject_id hash.
123    #[error("failed to compute subject_id: {0}")]
124    SubjectIdHash(String),
125
126    /// Failed to verify request signature.
127    #[error("request signature verification failed: {0}")]
128    SignatureVerification(String),
129
130    /// Wrapped ActorError for actor operations.
131    #[error("actor error: {0}")]
132    Actor(#[from] ActorError),
133}
134
135impl From<RequestHandlerError> for ActorError {
136    fn from(err: RequestHandlerError) -> Self {
137        match err {
138            RequestHandlerError::HelpersNotInitialized => {
139                Self::FunctionalCritical {
140                    description: err.to_string(),
141                }
142            }
143            RequestHandlerError::Actor(e) => e,
144            _ => Self::Functional {
145                description: err.to_string(),
146            },
147        }
148    }
149}
150
151#[derive(Debug, Error, Clone)]
152pub enum RequestManagerError {
153    #[error(
154        "the subject could not be created; the maximum limit has been reached."
155    )]
156    CheckLimit,
157    // Internal state errors
158    #[error("request is not set")]
159    RequestNotSet,
160
161    #[error("helpers (hash algorithm and network sender) are not initialized")]
162    HelpersNotInitialized,
163
164    #[error("invalid request state: expected {expected}, got {got}")]
165    InvalidRequestState {
166        expected: &'static str,
167        got: &'static str,
168    },
169
170    // Event request type errors
171    #[error("only Fact, Transfer and Confirm requests can be evaluated")]
172    InvalidEventRequestForEvaluation,
173
174    #[error("Confirm events on tracker subjects cannot be evaluated")]
175    ConfirmNotEvaluableForTracker,
176
177    // Protocol participant errors
178    #[error("no evaluators available for schema '{schema_id}'")]
179    NoEvaluatorsAvailable {
180        schema_id: String,
181        governance_id: DigestIdentifier,
182    },
183
184    #[error("no approvers available for schema '{schema_id}'")]
185    NoApproversAvailable {
186        schema_id: String,
187        governance_id: DigestIdentifier,
188    },
189
190    #[error("no validators available for schema '{schema_id}'")]
191    NoValidatorsAvailable {
192        schema_id: String,
193        governance_id: DigestIdentifier,
194    },
195
196    #[error(
197        "governance version changed for '{governance_id}': expected {expected}, got {current}"
198    )]
199    GovernanceVersionChanged {
200        governance_id: DigestIdentifier,
201        expected: u64,
202        current: u64,
203    },
204
205    // Governance errors
206    #[error("governance error: {0}")]
207    Governance(#[from] GovernanceError),
208
209    // Subject data errors
210    #[error("subject data not found for subject '{subject_id}'")]
211    SubjectDataNotFound { subject_id: String },
212
213    #[error("last ledger event not found for subject")]
214    LastLedgerEventNotFound,
215
216    #[error("failed to compute ledger hash: {details}")]
217    LedgerHashFailed { details: String },
218
219    // Protocol build errors
220    #[error("failed to build protocols: {0}")]
221    ProtocolsBuild(#[from] ProtocolsError),
222
223    #[error("ledger error: {0}")]
224    Ledger(#[from] LedgerError),
225
226    // Wrapped ActorError for operations that return ActorError
227    #[error("actor error: {0}")]
228    ActorError(#[from] ActorError),
229
230    #[error("Can not obtain SubjectData, is None")]
231    SubjecData,
232
233    #[error("In fact events, the signer has to be an issuer")]
234    NotIssuer,
235
236    #[error("In create tracker events, the signer has to be a creator")]
237    NotCreator,
238}
239
240/*
241Abort:
242Governance
243
244//////////////////////
245reboot:
246NoEvaluatorsAvailable
247NoApproversAvailable
248NoValidatorsAvailable
249*/