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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
use bls::PublicKey;
pub use sn_interface::messaging::data::Error as ErrorMsg;
use sn_interface::messaging::{
data::{CmdError, OperationId, QueryResponse},
Error as MessagingError, MsgId,
};
use sn_interface::types::Error as DtError;
use std::io;
use std::net::SocketAddr;
use thiserror::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[allow(clippy::large_enum_variant)]
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Initial network contact probe failed.")]
NetworkContact,
#[error("Genesis Key from the config and the PrefixMap mismatch. You may need to remove your prefixmap or update your config file.")]
GenesisKeyMismatch,
#[error("Error reading home dir for client")]
CouldNotReadHomeDir,
#[error("Error creating .safe dir for client")]
CouldNotCreateSafeDir,
#[error("Unexpected event received")]
ReceivedUnexpectedEvent,
#[error("Client has not yet acquired any network knowledge, so anything sent is guaranteed to have a lengthy AE process")]
NoNetworkKnowledge,
#[error("An error was returned from IncomingMessages on one of our connections")]
IncomingMessages,
#[error(
"Problem connecting to sufficient elders. A supermajority of responses is unobtainable. {connections} were connected to, {required} needed."
)]
InsufficientElderConnections {
connections: usize,
required: usize,
},
#[error(
"Problem finding sufficient elders. A supermajority of responses is unobtainable. {connections} were known in this section, {required} needed. Section pk: {section_pk:?}"
)]
InsufficientElderKnowledge {
connections: usize,
required: usize,
section_pk: PublicKey,
},
#[error("Error with Peer's connection: {0:?}")]
PeerConnection(SocketAddr),
#[error("Cannot store empty file.")]
EmptyFileProvided,
#[error("Not enough bytes for self-encryption. Try storing it as a SmallFile.")]
TooSmallForSelfEncryption,
#[error("You might need to pad the `SmallFile` contents and then store it as a `LargeFile`, as the encryption has made it slightly too big")]
SmallFilePaddingNeeded,
#[error(
"The provided bytes is too large to store as a `SmallFile`. Store as a LargeFile instead."
)]
TooLargeAsSmallFile,
#[error("Query timed out")]
QueryTimedOut,
#[error("Could not get an encryption object.")]
NoEncryptionObject,
#[error("Failed to obtain any response")]
NoResponse,
#[error("Could not retrieve the operation id of a query response")]
UnknownOperationId,
#[error("Unexpected response received when querying {0:?}")]
UnexpectedQueryResponse(QueryResponse),
#[error(transparent)]
NetworkDataError(#[from] DtError),
#[error(
"Error received from the network: {:?} Operationid: {:?}",
source,
op_id
)]
ErrorMsg {
source: ErrorMsg,
op_id: OperationId,
},
#[error("Error received from the network: {:?} for cmd: {:?}", source, msg_id)]
ErrorCmd {
source: ErrorMsg,
msg_id: MsgId,
},
#[error(transparent)]
MessagingProtocol(#[from] MessagingError),
#[error(transparent)]
SelfEncryption(#[from] self_encryption::Error),
#[error(transparent)]
ConfigError(#[from] serde_json::Error),
#[error(transparent)]
IoError(#[from] io::Error),
#[error(transparent)]
EndpointSetup(#[from] qp2p::ClientEndpointError),
#[error(transparent)]
QuicP2p(#[from] qp2p::RpcError),
#[error(transparent)]
QuicP2pConnection(#[from] qp2p::ConnectionError),
#[error(transparent)]
QuicP2pSend(#[from] qp2p::SendError),
#[error(transparent)]
Serialisation(#[from] Box<bincode::ErrorKind>),
#[error("Not all chunks were retrieved, expected {expected}, retrieved {retrieved}.")]
NotEnoughChunksRetrieved {
expected: usize,
retrieved: usize,
},
#[error("Not all data was chunked, expected {expected}, but we have {chunked}.)")]
NotAllDataWasChunked {
expected: usize,
chunked: usize,
},
}
impl From<(CmdError, MsgId)> for Error {
fn from((error, msg_id): (CmdError, MsgId)) -> Self {
let CmdError::Data(source) = error;
Error::ErrorCmd { source, msg_id }
}
}
impl From<(ErrorMsg, OperationId)> for Error {
fn from((source, op_id): (ErrorMsg, OperationId)) -> Self {
Self::ErrorMsg { source, op_id }
}
}
impl From<qp2p::RecvError> for Error {
fn from(error: qp2p::RecvError) -> Self {
Self::QuicP2p(error.into())
}
}