1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use crate::peer_list::PeerState;
use std::{
fmt::{self, Display, Formatter},
result,
};
#[derive(PartialEq, Eq, Debug)]
pub enum Error {
MismatchedPayload,
UnknownPayload,
MissingVotes,
SignatureFailure,
UnknownPeer,
InvalidPeerState {
required: PeerState,
actual: PeerState,
},
InvalidSelfState {
required: PeerState,
actual: PeerState,
},
InvalidEvent,
UnknownSelfParent,
UnknownOtherParent,
DuplicateVote,
PrematureGossip,
InvalidMessage,
DuplicateMessage,
FailedDkg,
Logic,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Error::MismatchedPayload => write!(
f,
"The payload of the vote doesn't match the payload of targeted block."
),
Error::UnknownPayload => write!(
f,
"The payload hash doesn't correspond to any payload known to our node."
),
Error::MissingVotes => write!(f, "Block cannot be created with no votes"),
Error::SignatureFailure => write!(
f,
"The message or signature might be corrupted, or the signer is wrong."
),
Error::UnknownPeer => write!(f, "The peer_id is not known to our node's peer_list."),
Error::InvalidPeerState { required, actual } => write!(
f,
"The peer is in invalid state (required: {:?}, actual: {:?}).",
required, actual
),
Error::InvalidSelfState { required, actual } => write!(
f,
"Our node is in invalid state (required: {:?}, actual: {:?}).",
required, actual
),
Error::InvalidEvent => write!(f, "The given event is invalid or malformed."),
Error::UnknownSelfParent => {
write!(f, "The event's self-parent is unknown to this node.")
}
Error::UnknownOtherParent => {
write!(f, "The event's other-parent is unknown to this node.")
}
Error::DuplicateVote => write!(f, "Our node has already voted for this network event."),
Error::PrematureGossip => write!(
f,
"The peer did not know we could handle a message from it."
),
Error::InvalidMessage => write!(f, "This non-empty message is invalid."),
Error::DuplicateMessage => write!(f, "This message has already been handled."),
Error::FailedDkg => write!(f, "The requested DKG could not proceed."),
Error::Logic => write!(
f,
"This is a logic error and represents a flaw in the code."
),
}
}
}
pub type Result<T> = result::Result<T, Error>;