error.rs
1 //! Core library errors. 2 3 use crate::mls_crypto; 4 5 #[derive(Debug, thiserror::Error)] 6 pub enum CoreError { 7 /// Identity error. 8 #[error("Identity error: {0}")] 9 IdentityError(#[from] mls_crypto::IdentityError), 10 11 /// MLS service error. 12 #[error("MLS error: {0}")] 13 MlsServiceError(#[from] mls_crypto::MlsServiceError), 14 15 /// Storage error. 16 #[error("Storage error: {0}")] 17 StorageError(#[from] mls_crypto::StorageError), 18 19 #[error("Consensus error: {0}")] 20 ConsensusError(#[from] hashgraph_like_consensus::error::ConsensusError), 21 22 #[error("System time error: {0}")] 23 SystemTimeError(#[from] std::time::SystemTimeError), 24 25 /// Message encoding/decoding error. 26 #[error("Message error: {0}")] 27 MessageError(#[from] prost::DecodeError), 28 29 /// JSON error. 30 #[error("JSON error: {0}")] 31 JsonError(#[from] serde_json::Error), 32 33 /// MLS group is not initialized for this handle. 34 #[error("MLS group not initialized")] 35 MlsGroupNotInitialized, 36 37 /// Steward is not set for this group handle. 38 #[error("Steward not set")] 39 StewardNotSet, 40 41 /// No proposals available for the requested operation. 42 #[error("No proposals available")] 43 NoProposals, 44 45 #[error("Invalid group update request")] 46 InvalidGroupUpdateRequest, 47 48 #[error("Invalid subtopic: {0}")] 49 InvalidSubtopic(String), 50 51 /// Emergency criteria proposals found in approved queue during batch creation. 52 /// This indicates a bug: emergency proposals should be removed by 53 /// apply_consensus_result before create_batch_proposals is called. 54 #[error( 55 "Emergency criteria proposals found in approved queue (ids: {proposal_ids:?}). \ 56 They should have been removed by apply_consensus_result." 57 )] 58 UnexpectedEmergencyProposals { proposal_ids: Vec<u32> }, 59 60 /// The consensus outcome does not match the handle's ownership state. 61 /// For example, `ApprovedOwner` was passed but the handle does not own the proposal, 62 /// or `Approved { payload }` was passed but the handle does own it. 63 #[error("Invalid consensus outcome: {0}")] 64 InvalidConsensusOutcome(String), 65 66 /// The proposal ID was not found in the handle's voting or approved proposals. 67 #[error("Proposal not found: {0}")] 68 ProposalNotFound(u32), 69 } 70 71 impl From<mls_crypto::MlsError> for CoreError { 72 fn from(e: mls_crypto::MlsError) -> Self { 73 match e { 74 mls_crypto::MlsError::Identity(e) => CoreError::IdentityError(e), 75 mls_crypto::MlsError::Service(e) => CoreError::MlsServiceError(e), 76 mls_crypto::MlsError::Storage(e) => CoreError::StorageError(e), 77 } 78 } 79 }