Skip to main content

ave_core/subject/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error, Clone)]
4pub enum SubjectError {
5    // Subject state errors
6    #[error("subject is no longer active")]
7    SubjectInactive,
8
9    #[error("subject schema id is invalid")]
10    InvalidSchemaId,
11
12    // Signature and verification errors
13    #[error("signature verification failed: {context}")]
14    SignatureVerificationFailed { context: String },
15
16    #[error("incorrect signer: expected {expected}, got {actual}")]
17    IncorrectSigner { expected: String, actual: String },
18
19    #[error(
20        "event request signer is invalid for {event}: expected {expected}, got {actual}"
21    )]
22    InvalidEventRequestSigner {
23        event: String,
24        expected: String,
25        actual: String,
26    },
27
28    #[error("validation request signature is invalid")]
29    InvalidValidationRequestSignature,
30
31    #[error("validator signature could not be verified")]
32    InvalidValidatorSignature,
33
34    // Event and ledger errors
35    #[error(
36        "event is not the next one to be applied: expected sn {expected}, got {actual}"
37    )]
38    InvalidSequenceNumber { expected: u64, actual: u64 },
39
40    #[error("previous ledger event hash does not match")]
41    PreviousHashMismatch,
42
43    #[error("subject id mismatch: expected {expected}, got {actual}")]
44    SubjectIdMismatch { expected: String, actual: String },
45
46    #[error("ledger event hash mismatch: expected {expected}, got {actual}")]
47    LedgerHashMismatch { expected: String, actual: String },
48
49    #[error("event type does not match protocols")]
50    EventProtocolMismatch,
51
52    #[error("event should be {expected} but got {actual}")]
53    UnexpectedEventType { expected: String, actual: String },
54
55    // Protocol-specific errors
56    #[error("fact event received but should be confirm or reject event")]
57    UnexpectedFactEvent,
58
59    #[error("transfer event received but should be confirm or reject event")]
60    UnexpectedTransferEvent,
61
62    #[error("EOL event received but should be confirm or reject event")]
63    UnexpectedEOLEvent,
64
65    #[error("confirm event received but new_owner is None")]
66    ConfirmWithoutNewOwner,
67
68    #[error("reject event received but new_owner is None")]
69    RejectWithoutNewOwner,
70
71    // Validation errors
72    #[error("quorum is not valid")]
73    InvalidQuorum,
74
75    #[error("validation request hash does not match")]
76    ValidationRequestHashMismatch,
77
78    #[error("validators and quorum could not be obtained: {details}")]
79    ValidatorsRetrievalFailed { details: String },
80
81    // Metadata errors
82    #[error("event metadata does not match subject metadata")]
83    MetadataMismatch,
84
85    #[error("validation metadata must be of type Metadata in creation event")]
86    InvalidValidationMetadata,
87
88    #[error(
89        "validation metadata must be of type ModifiedMetadataHash in non-creation event"
90    )]
91    InvalidNonCreationValidationMetadata,
92
93    #[error("in creation event, sequence number must be 0")]
94    InvalidCreationSequenceNumber,
95
96    #[error("previous ledger event hash must be empty in creation event")]
97    NonEmptyPreviousHashInCreation,
98
99    // Patch and state errors
100    #[error("failed to apply patch: {details}")]
101    PatchApplicationFailed { details: String },
102
103    #[error("failed to convert ValueWrapper into Patch: {details}")]
104    PatchConversionFailed { details: String },
105
106    #[error("evaluation was satisfactory but there was no approval")]
107    MissingApprovalAfterEvaluation,
108
109    #[error("evaluation was not satisfactory but there is approval")]
110    UnexpectedApprovalAfterFailedEvaluation,
111
112    // Governance-specific errors
113    #[error("failed to convert properties into GovernanceData: {details}")]
114    GovernanceDataConversionFailed { details: String },
115
116    #[error(
117        "schema_id is Governance, but cannot convert properties: {details}"
118    )]
119    GovernancePropertiesConversionFailed { details: String },
120
121    #[error("{what} '{who}' is not a member")]
122    NotAMember { what: String, who: String },
123
124    #[error("schema '{schema_id}' has no policies")]
125    SchemaNoPolicies { schema_id: String },
126
127    #[error("schema '{schema_id}' is not a schema")]
128    InvalidSchema { schema_id: String },
129
130    // Tracker-specific errors
131    #[error("number of subjects that can be created has not been found")]
132    MaxSubjectCreationNotFound,
133
134    #[error("protocols data is for Governance but this is a Tracker")]
135    GovernanceProtocolsInTracker,
136
137    #[error("protocols data is for Tracker but this is a Governance")]
138    TrackerProtocolsInGovernance,
139
140    #[error(
141        "node configured for clear events cannot accept tracker opaque events"
142    )]
143    OnlyClearEventsCannotAcceptTrackerOpaque,
144
145    #[error("governance fact event cannot contain viewpoints")]
146    GovernanceFactViewpointsNotAllowed,
147
148    // Hash errors
149    #[error("failed to create hash: {details}")]
150    HashCreationFailed { details: String },
151
152    #[error("validation request hash could not be obtained: {details}")]
153    ValidationRequestHashFailed { details: String },
154
155    #[error("modified metadata hash could not be obtained: {details}")]
156    ModifiedMetadataHashFailed { details: String },
157
158    #[error(
159        "modified metadata without properties hash mismatch: expected {expected}, got {actual}"
160    )]
161    ModifiedMetadataWithoutPropertiesHashMismatch {
162        expected: String,
163        actual: String,
164    },
165
166    #[error("properties hash mismatch: expected {expected}, got {actual}")]
167    PropertiesHashMismatch { expected: String, actual: String },
168
169    #[error("event request hash mismatch: expected {expected}, got {actual}")]
170    EventRequestHashMismatch { expected: String, actual: String },
171
172    #[error("viewpoints hash mismatch: expected {expected}, got {actual}")]
173    ViewpointsHashMismatch { expected: String, actual: String },
174
175    // Actor and system errors
176    #[error("actor not found: {path}")]
177    ActorNotFound { path: String },
178
179    #[error("unexpected response from {path}: expected {expected}")]
180    UnexpectedResponse { path: String, expected: String },
181
182    #[error("helper not found: {helper}")]
183    HelperNotFound { helper: String },
184
185    #[error("cannot obtain {what}")]
186    CannotObtain { what: String },
187
188    // General errors
189    #[error("{0}")]
190    Generic(String),
191}
192
193impl From<String> for SubjectError {
194    fn from(s: String) -> Self {
195        Self::Generic(s)
196    }
197}
198
199impl From<&str> for SubjectError {
200    fn from(s: &str) -> Self {
201        Self::Generic(s.to_string())
202    }
203}