1use serde::{Deserialize, Serialize};
9use thiserror::Error;
10
11#[derive(Clone, Debug, Deserialize, Error, PartialEq, Serialize)]
12pub enum Error {
14 #[error("Provided epoch, {0}, does not match expected epoch, {1}")]
15 IncorrectEpoch(u64, u64),
16 #[error("block has next round that wraps around: {0}")]
17 IncorrectRound(u64),
18 #[error("Provided round, {0}, is incompatible with last voted round, {1}")]
19 IncorrectLastVotedRound(u64, u64),
20 #[error("Provided round, {0}, is incompatible with preferred round, {1}")]
21 IncorrectPreferredRound(u64, u64),
22 #[error("Unable to verify that the new tree extends the parent: {0}")]
23 InvalidAccumulatorExtension(String),
24 #[error("Internal error: {0}")]
25 InternalError(String),
26 #[error("Invalid proposal: {0}")]
27 InvalidProposal(String),
28 #[error("Invalid QC: {0}")]
29 InvalidQuorumCertificate(String),
30 #[error("{0} is not set, SafetyRules is not initialized")]
31 NotInitialized(String),
32 #[error("Data not found in secure storage: {0}")]
33 SecureStorageMissingDataError(String),
34 #[error("Unexpected error returned by secure storage: {0}")]
35 SecureStorageUnexpectedError(String),
36 #[error("Serialization error: {0}")]
37 SerializationError(String),
38 #[error("Validator key not found: {0}")]
39 ValidatorKeyNotFound(String),
40 #[error(
41 "The validator is not in the validator set. Address not in set: {0}"
42 )]
43 ValidatorNotInSet(String),
44 #[error("Vote proposal missing expected signature")]
45 VoteProposalSignatureNotFound,
46}
47
48impl From<bcs::Error> for Error {
49 fn from(error: bcs::Error) -> Self {
50 Self::SerializationError(format!("{}", error))
51 }
52}
53
54impl From<diem_secure_storage::Error> for Error {
55 fn from(error: diem_secure_storage::Error) -> Self {
56 match error {
57 diem_secure_storage::Error::PermissionDenied => {
58 panic!(
66 "A permission error was thrown: {:?}. Maybe the storage token needs to be renewed?",
67 error
68 );
69 }
70 diem_secure_storage::Error::KeyVersionNotFound(_, _)
71 | diem_secure_storage::Error::KeyNotSet(_) => {
72 Self::SecureStorageMissingDataError(error.to_string())
73 }
74 _ => Self::SecureStorageUnexpectedError(error.to_string()),
75 }
76 }
77}