holochain_integrity_types/countersigning/
error.rs1use crate::Role;
2
3#[derive(Debug, PartialEq, Eq)]
5pub enum CounterSigningError {
6 AgentIndexOutOfBounds,
8 MissingResponse,
10 CounterSigningSessionResponsesLength(usize, usize),
12 CounterSigningSessionResponsesOrder(u8, usize),
14 EnzymeMismatch(
16 Option<(holo_hash::AgentPubKey, Vec<Role>)>,
17 Option<(holo_hash::AgentPubKey, Vec<Role>)>,
18 ),
19 NonEnzymaticOptionalSigners,
21 AgentsLength(usize),
23 OptionalAgentsLength(u8, usize),
25 MinOptionalAgents(u8, usize),
27 AgentsDupes(Vec<holo_hash::AgentPubKey>),
29 CounterSigningSessionTimes(crate::CounterSigningSessionTimes),
31}
32
33impl std::error::Error for CounterSigningError {}
34
35impl core::fmt::Display for CounterSigningError {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 match self {
38 CounterSigningError::AgentIndexOutOfBounds => {
39 write!(f, "Agent index is out of bounds for the signing session.")
40 }
41 CounterSigningError::MissingResponse => write!(
42 f,
43 "Attempted to build CounterSigningSessionData with an empty response vector."
44 ),
45 CounterSigningError::CounterSigningSessionResponsesLength(resp, num_agents) => {
46 write!(f,
47 "The countersigning session responses ({}) did not match the number of signing agents ({})",
48 resp,
49 num_agents
50 )
51 }
52 CounterSigningError::CounterSigningSessionResponsesOrder(index, pos) => write!(f,
53 "The countersigning session response with agent index {} was found in index position {}",
54 index, pos
55 ),
56 CounterSigningError::EnzymeMismatch(required_signer, optional_signer) => write!(f,
57 "The enzyme is mismatche for required signer {:?} and optional signer {:?}",
58 required_signer, optional_signer
59
60 ),
61 CounterSigningError::NonEnzymaticOptionalSigners => write!(f, "There are optional signers without an enzyme."),
62 CounterSigningError::AgentsLength(len) => {
63 write!(f, "The signing agents list is too long or short {}", len)
64 },
65 CounterSigningError::OptionalAgentsLength(min, len) => {
66 write!(f, "The optional signing agents list length is {} which is less than the minimum {} required to sign", len, min)
67 },
68 CounterSigningError::MinOptionalAgents(min, len) => {
69 write!(f, "The minimum optional agents {} is not a majority of {}", min, len)
70 },
71 CounterSigningError::AgentsDupes(agents) => write!(
72 f,
73 "The signing agents list contains duplicates {:?}",
74 agents
75 ),
76 CounterSigningError::CounterSigningSessionTimes(times) => write!(
77 f,
78 "The countersigning session times were not valid {:?}",
79 times
80 ),
81 }
82 }
83}