Skip to main content

ave_core/request/
error.rs

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