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 ({resp}) did not match the number of signing agents ({num_agents})"
48 )
49 }
50 CounterSigningError::CounterSigningSessionResponsesOrder(index, pos) => write!(f,
51 "The countersigning session response with agent index {index} was found in index position {pos}"
52 ),
53 CounterSigningError::EnzymeMismatch(required_signer, optional_signer) => write!(f,
54 "The enzyme is mismatche for required signer {required_signer:?} and optional signer {optional_signer:?}"
55
56 ),
57 CounterSigningError::NonEnzymaticOptionalSigners => write!(f, "There are optional signers without an enzyme."),
58 CounterSigningError::AgentsLength(len) => {
59 write!(f, "The signing agents list is too long or short {len}")
60 },
61 CounterSigningError::OptionalAgentsLength(min, len) => {
62 write!(f, "The optional signing agents list length is {len} which is less than the minimum {min} required to sign")
63 },
64 CounterSigningError::MinOptionalAgents(min, len) => {
65 write!(f, "The minimum optional agents {min} is not a majority of {len}")
66 },
67 CounterSigningError::AgentsDupes(agents) => write!(
68 f,
69 "The signing agents list contains duplicates {agents:?}"
70 ),
71 CounterSigningError::CounterSigningSessionTimes(times) => write!(
72 f,
73 "The countersigning session times were not valid {times:?}"
74 ),
75 }
76 }
77}