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
use sn_data_types::{Error as DtError, PublicKey};
use sn_messaging::{client::Error as ErrorMessage, MessageId};
use std::io;
use thiserror::Error;
use xor_name::XorName;
#[allow(clippy::large_enum_variant)]
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Attempted Adult operation when not an Adult")]
NotAnAdult,
#[error("Attempted Elder operation when not an Elder")]
NotAnElder,
#[error("Balance already exists.")]
BalanceExists,
#[error("Not enough space")]
NotEnoughSpace,
#[error("Not section public key returned from routing")]
NoSectionPublicKey,
#[error("PublicKey provided was not identified as a section {0}")]
UnknownSectionKey(PublicKey),
#[error("PublicKey provided for signing as elder is not a BLS PublicKeyShare")]
ProvidedPkIsNotBlsShare,
#[error("PublicKey provided for signing as elder is not a BLS")]
ProvidedPkIsNotBls,
#[error("Not section public key set returned from routing")]
NoSectionPublicKeySet,
#[error("Not section public key returned from routing for xorname {0}")]
NoSectionPublicKeyKnown(XorName),
#[error("Cannot parse reward proposal at this stage")]
InvalidRewardStage,
#[error("Node not found for rewards")]
NodeNotFoundForReward,
#[error("No chunks held at node")]
NodeDoesNotHoldChunks,
#[error("No holders found for chunk")]
NoHoldersOfChunk,
#[error("No such chunk")]
NoSuchChunk,
#[error("Cannot process fund churn message")]
NotChurningFunds,
#[error("Could not create temp store: {0}")]
TempDirCreationFailed(String),
#[error("Could not fetch StoreId")]
NoStoreId,
#[error("Could not combine signatures")]
CouldNotCombineSignatures,
#[error("Data already exists at this node")]
DataExists,
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("JSON serialisation error:: {0}")]
JsonSerialisation(#[from] serde_json::Error),
#[error("Bincode error:: {0}")]
Bincode(#[from] bincode::Error),
#[error("Client message error:: {0}")]
ClientMessage(#[from] sn_messaging::client::Error),
#[error("Network message error:: {0}")]
Message(#[from] sn_messaging::Error),
#[error("PickleDb error:: {0}")]
PickleDb(#[from] pickledb::error::Error),
#[error("Network data error:: {0}")]
NetworkData(#[from] sn_data_types::Error),
#[error("Transfer data error:: {0}")]
Transfer(#[from] sn_transfers::Error),
#[error("Routing error:: {0}")]
Routing(#[from] sn_routing::Error),
#[error("Onboarding error")]
Onboarding,
#[error("Transfer has already been registered")]
TransferAlreadyRegistered,
#[error("Signed transfer for Dot: '{0:?}' is not valid. Debit or credit are missing")]
InvalidSignedTransfer(crdts::Dot<PublicKey>),
#[error("Propagated Credit Agreement proof is not valid. Proof received: {0:?}")]
InvalidPropagatedTransfer(sn_data_types::CreditAgreementProof),
#[error("Message with id: '{0:?}' is invalid. {1}")]
InvalidMessage(MessageId, String),
#[error("Provided PublicKey is not a valid owner. Provided PublicKey: {0}")]
InvalidOwners(PublicKey),
#[error("Invalid operation: {0}")]
InvalidOperation(String),
#[error("No mapping to sn_messages error is set up for this NodeError {0}")]
NoErrorMapping(String),
#[error("Logic error: {0}")]
Logic(String),
#[error("Configuration error: {0}")]
Configuration(String),
}
pub(crate) fn convert_to_error_message(error: Error) -> Result<sn_messaging::client::Error> {
match error {
Error::InvalidOperation(_msg) => Ok(ErrorMessage::InvalidOperation),
Error::InvalidOwners(key) => Ok(ErrorMessage::InvalidOwners(key)),
Error::InvalidSignedTransfer(_) => Ok(ErrorMessage::InvalidSignature),
Error::TransferAlreadyRegistered => Ok(ErrorMessage::TransactionIdExists),
Error::NoSuchChunk => Ok(ErrorMessage::NoSuchData),
Error::NotEnoughSpace => Ok(ErrorMessage::NotEnoughSpace),
Error::BalanceExists => Ok(ErrorMessage::BalanceExists),
Error::TempDirCreationFailed(_) => Ok(ErrorMessage::FailedToWriteFile),
Error::DataExists => Ok(ErrorMessage::DataExists),
Error::NetworkData(error) => convert_dt_error_to_error_message(error),
error => Err(Error::NoErrorMapping(error.to_string())),
}
}
pub(crate) fn convert_dt_error_to_error_message(
error: DtError,
) -> Result<sn_messaging::client::Error> {
match error {
DtError::InvalidOperation => Ok(ErrorMessage::InvalidOperation),
DtError::PolicyNotSet => Ok(ErrorMessage::PolicyNotSet),
DtError::NoSuchEntry => Ok(ErrorMessage::NoSuchEntry),
DtError::CrdtUnexpectedState => Ok(ErrorMessage::CrdtUnexpectedState),
DtError::OpNotCausallyReady => Ok(ErrorMessage::OpNotCausallyReady),
DtError::AccessDenied(pk) => Ok(ErrorMessage::AccessDenied(pk)),
error => Err(Error::NoErrorMapping(error.to_string())),
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;