-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherrors.rs
More file actions
180 lines (168 loc) · 5.7 KB
/
Copy patherrors.rs
File metadata and controls
180 lines (168 loc) · 5.7 KB
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
//use colored::Colorize;
use thiserror::Error;
macro_rules! root_errors {
[$(
$errname:ident : $msg:literal {
$(
//nested should not exist because all the errors are $var + "Kind"
//but concat_ident!() isn't stable and doesn't work well
$var:ident($nested:ident)
),*
}
),*] => {
$(
#[derive(Debug, Error)]
pub enum $errname {
$(
#[error("{} -> {}: {0}", $msg, stringify!($var))]
$var($nested),
)*
}
)*
};
}
macro_rules! sub_errors {
[$(
$name:ident {
$(
$var:ident : $msg:literal
),*
}
),*] => {
$(
#[derive(Debug, Error)]
pub enum $name {
$(
#[error($msg)]
$var,
)*
}
)*
}
}
// #[macro_export]
// macro_rules! report {
// ($ctx:expr, $msg:expr) => {
// return Err(
// Report::new($ctx)
// .attach_printable($msg)
// )
// };
// }
root_errors![
ToolsError : "Error ocurred while using a tool function" {
Biguint(BiguintErrorKind),
Zstd(ZstdErrorKind)
},
TransactionError : "Error ocurred while operating on a transaction" {
Tx(TxErrorKind)
},
MerkleTreeError : "Error ocurred while operating on the merkletree" {
TreeError(MerkleTreeErrorKind)
},
BlockError : "Error ocurred while operating on a block" {
BasicInfo(BasicInfoErrorKind),
TransactionToken(TxTokenErrorKind),
TransactionBlock(TxBlockErrorKind),
DerivativeBlock(DerivativeBlockErrorKind),
SummarizeBlock(SummarizeBlockErrorKind),
HeaderError(DumpHeadersErrorKind),
NotImplemented(NotImplementedKind)
},
BlockChainTreeError : "Error ocurred while operating on the blockchain tree" {
Chain(ChainErrorKind),
DerivativeChain(DerivChainErrorKind),
BlockChainTree(BCTreeErrorKind)
},
DumpHeadersError : "Error with dump header"{
DumpHeadersError(DumpHeadersErrorKind)
}
];
sub_errors![
NotImplementedKind {
Token: "Token is not implemented yet"
},
DumpHeadersErrorKind {
UknownHeader: "Uknown header",
WrongHeader: "Wrong header"
},
BiguintErrorKind {
Dump: "failed to dump biguint, amount of bunches larger than 255",
Load: "failed to load biguint (data length < bytes)"
},
ZstdErrorKind {
CompressingFile: "failed to compress file with zstd",
DecompressingFile: "failed to decompress file with zstd"
},
TxErrorKind {
Verify: "failed to verify transaction",
Dump: "failed to dump transaction (amount)",
Parse: "failed to parse transaction"
},
MerkleTreeErrorKind {
GettingProof: "failed to get proof"
},
BasicInfoErrorKind {
Dump: "failed to dump basic info",
Parse: "failed to parse basic info"
},
TxTokenErrorKind {
SettingTx: "failed to set transaction (already set)",
SettingToken: "failed to set token (already set)",
Dump: "failed to dump (token or transaction)"
},
TxBlockErrorKind {
BuildingMerkleTree: "failed to build merkle tree",
Dump: "failed to dump",
Parse: "failed to parse"
},
DerivativeBlockErrorKind {
Dump: "failed to dump",
Parse: "failed to parse"
},
SummarizeBlockErrorKind {
Dump: "failed to dump",
Parse: "failed to parse",
Hash: "failed to hash (couldn't dump)"
},
ChainErrorKind {
Init: "failed to create a new chain",
AddingBlock: "failed to add block",
AddingTransaction: "failed to add transaction",
FindByHeight: "failed to find block by height",
FindByHashE: "failed to find by hash",
DumpConfig: "failed to dump config",
InitWithoutConfig: "failed to create a new chain without config",
FindTransaction: "failed to find transaction",
FailedToVerify: "failed to verify block",
FailedToHashBlock: "failed to hash block",
FailedToRemoveHeighReference: "failed to remove height reference",
FailedToRemoveTransaction: "failed to remove transaction"
},
DerivChainErrorKind {
Init: "failed to create a new derivative chain",
AddingBlock: "failed to add block",
FindByHeight: "failed to find block by height",
FindByHash: "failed to find by hash",
DumpConfig: "failed to dump config",
InitWithoutConfig: "failed to create a new chain without config"
},
BCTreeErrorKind {
Init: "failed to init the blockchain tree (with config)",
InitWithoutConfig: "failed to init the blockchain tree (with config)",
DumpPool: "failed to dump pool",
DumpDb: "failed to dump database",
GetDerivChain: "failed to get the derivative chain",
CreateDerivChain: "failed to create the derivative chain",
CheckMainFolders: "failed to check and fix the main folders",
AddFunds: "failed to add funds",
DecreaseFunds: "failed to decrease funds",
GetFunds: "failed to get funds",
GetOldFunds: "failed to get funds from old summary db",
MoveSummaryDB: "failed to move summary database",
NewTransaction: "failed to create new transaction",
CreateMainChainBlock: "failed to create new block for the main chain",
WrongPow: "supplied pow does not satisfy requirements",
SummarizeBlockWrongTransactionsAmount: "summarization block should not have transactions"
}
];