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("Invalid EpochChangeProof: {0}")]
25 InvalidEpochChangeProof(String),
26 #[error("Internal error: {0}")]
27 InternalError(String),
28 #[error("No next_epoch_state specified in the provided Ledger Info")]
29 InvalidLedgerInfo,
30 #[error("Invalid proposal: {0}")]
31 InvalidProposal(String),
32 #[error("Invalid QC: {0}")]
33 InvalidQuorumCertificate(String),
34 #[error("{0} is not set, SafetyRules is not initialized")]
35 NotInitialized(String),
36 #[error("Data not found in secure storage: {0}")]
37 SecureStorageMissingDataError(String),
38 #[error("Unexpected error returned by secure storage: {0}")]
39 SecureStorageUnexpectedError(String),
40 #[error("Serialization error: {0}")]
41 SerializationError(String),
42 #[error("Validator key not found: {0}")]
43 ValidatorKeyNotFound(String),
44 #[error(
45 "The validator is not in the validator set. Address not in set: {0}"
46 )]
47 ValidatorNotInSet(String),
48 #[error("Vote proposal missing expected signature")]
49 VoteProposalSignatureNotFound,
50}
51
52impl From<bcs::Error> for Error {
53 fn from(error: bcs::Error) -> Self {
54 Self::SerializationError(format!("{}", error))
55 }
56}
57
58impl From<diem_secure_net::Error> for Error {
59 fn from(error: diem_secure_net::Error) -> Self {
60 Self::InternalError(error.to_string())
61 }
62}
63
64impl From<diem_secure_storage::Error> for Error {
65 fn from(error: diem_secure_storage::Error) -> Self {
66 match error {
67 diem_secure_storage::Error::PermissionDenied => {
68 panic!(
76 "A permission error was thrown: {:?}. Maybe the storage token needs to be renewed?",
77 error
78 );
79 }
80 diem_secure_storage::Error::KeyVersionNotFound(_, _)
81 | diem_secure_storage::Error::KeyNotSet(_) => {
82 Self::SecureStorageMissingDataError(error.to_string())
83 }
84 _ => Self::SecureStorageUnexpectedError(error.to_string()),
85 }
86 }
87}