forked from hyperledger/indy-plenum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.py
355 lines (215 loc) · 7.76 KB
/
exceptions.py
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
from re import compile
# TODO
# - review the list and remove obsolete ones
# - refactor hierarchy of exceptions taking into account ones
# from common/exceptions.py
from typing import Any, Callable
from common.exceptions import LogicError
from plenum.common.constants import CURRENT_PROTOCOL_VERSION
from plenum.server.suspicion_codes import Suspicion
class ReqInfo:
def __init__(self, identifier=None, reqId=None):
self.identifier = identifier
self.reqId = reqId
class NodeError(Exception):
pass
class PortNotAvailableForNodeWebServer(NodeError):
pass
class RemoteError(NodeError):
def __init__(self, remote):
self.remote = remote
class RemoteNotFound(RemoteError):
pass
class BaseExc(Exception):
# def __init__(self, code: int=None, reason: str=None):
# self.code = code
# self.reason = reason
def __str__(self):
return "{}{}".format(self.__class__.__name__, self.args)
class SigningException(BaseExc):
pass
class CouldNotAuthenticate(SigningException, ReqInfo):
code = 110
reason = 'could not authenticate, verkey for {} cannot be found'
def __init__(self, identifier, *args, **kwargs):
self.reason = self.reason.format(identifier)
ReqInfo.__init__(self, *args, **kwargs)
def __str__(self):
return self.reason
class MissingSignature(SigningException):
code = 120
reason = 'missing signature'
class EmptySignature(SigningException, ReqInfo):
code = 121
reason = 'empty signature'
def __init__(self, *args, **kwargs):
ReqInfo.__init__(self, *args, **kwargs)
class InvalidSignatureFormat(SigningException, ReqInfo):
code = 123
reason = 'invalid signature format'
def __init__(self, *args, **kwargs):
ReqInfo.__init__(self, *args, **kwargs)
class InvalidSignature(SigningException, ReqInfo):
code = 125
reason = 'invalid signature'
def __init__(self, *args, **kwargs):
ReqInfo.__init__(self, *args, **kwargs)
class InsufficientSignatures(SigningException, ReqInfo):
code = 126
reason = 'insufficient signatures, {} provided but {} required'
def __init__(self, provided, required, *args, **kwargs):
self.reason = self.reason.format(provided, required)
ReqInfo.__init__(self, *args, **kwargs)
def __str__(self):
return self.reason
class InsufficientCorrectSignatures(SigningException, ReqInfo):
code = 127
reason = (
'insufficient number of valid signatures, {} is required but {} valid and {} invalid have been provided. '
'The following signatures are invalid: {}'
)
def __init__(self, required_sig_cnt, valid_sig_cnt, invalid_sigs, *args, **kwargs):
invalid_sigs_str = '; '.join('did={}, signature={}'.format(k, v) for k, v in invalid_sigs.items())
self.reason = self.reason.format(required_sig_cnt, valid_sig_cnt, len(invalid_sigs), invalid_sigs_str)
ReqInfo.__init__(self, *args, **kwargs)
def __str__(self):
return self.reason
class MissingIdentifier(SigningException):
code = 130
reason = 'missing identifier'
class EmptyIdentifier(SigningException):
code = 131
reason = 'empty identifier'
class UnknownIdentifier(SigningException, ReqInfo):
code = 133
reason = 'unknown identifier'
def __init__(self, *args, **kwargs):
ReqInfo.__init__(self, *args, **kwargs)
class InvalidIdentifier(SigningException, ReqInfo):
code = 135
reason = 'invalid identifier'
def __init__(self, *args, **kwargs):
ReqInfo.__init__(self, *args, **kwargs)
class UnregisteredIdentifier(SigningException):
code = 136
reason = 'provided owner identifier not registered with agent'
class NoAuthenticatorFound(SigningException):
code = 137
class KeysNotFoundException(Exception):
code = 141
reason = 'Keys not found in the keep for {}. ' \
'To generate them run script '
class InvalidKey(Exception):
code = 142
reason = 'invalid key'
class SuspiciousNode(BaseExc):
def __init__(self, node: str, suspicion: Suspicion, offendingMsg):
node = node.decode() if isinstance(node, bytes) else node
self.code = suspicion.code if suspicion else None
self.reason = suspicion.reason if suspicion else None
p = compile(r'(\b\w+)(:(\d+))?')
m = p.match(node)
self.node = m.groups()[0] if m else node
self.offendingMsg = offendingMsg
def __repr__(self):
return "Error code: {}. {}".format(self.code, self.reason)
class SuspiciousClient(BaseExc, ReqInfo):
pass
class InvalidMessageException(BaseExc):
pass
class InvalidNodeMessageException(InvalidMessageException):
pass
class InvalidClientMessageException(InvalidMessageException):
def __init__(self, identifier, reqId, reason=None, code=None):
self.code = code
self.identifier = identifier
self.reqId = reqId
self.reason = reason
class InvalidNodeMsg(InvalidNodeMessageException):
pass
class MismatchedMessageReplyException(InvalidNodeMsg):
pass
class IncorrectMessageForHandlingException(InvalidNodeMsg):
def __init__(self, msg: Any, reason: str, log_method: Callable, *args, **kwargs):
super().__init__(*args, **kwargs)
self.log_method = log_method
self.msg = msg
self.reason = reason
self.args = args
class MissingNodeOp(InvalidNodeMsg):
pass
class InvalidNodeOp(InvalidNodeMsg):
pass
class InvalidNodeMsgType(InvalidNodeMsg):
pass
class InvalidClientRequest(InvalidClientMessageException):
pass
class InvalidClientMsgType(InvalidClientRequest):
pass
class InvalidClientOp(InvalidClientRequest):
pass
class InvalidClientTaaAcceptanceError(InvalidClientRequest):
pass
class UnauthorizedClientRequest(InvalidClientMessageException):
pass
class StorageException(Exception):
pass
class DataDirectoryNotFound(StorageException):
pass
class DBConfigNotFound(StorageException):
pass
class KeyValueStorageConfigNotFound(StorageException):
pass
class UnsupportedOperation(Exception):
pass
class DidMethodNotFound(Exception):
pass
class BlowUp(BaseException):
"""
An exception designed to blow through fault barriers. Useful during testing.
Derives from BaseException so asyncio will let it through.
"""
class ProdableAlreadyAdded(Exception):
pass
class NoConsensusYet(Exception):
pass
class NotConnectedToAny(Exception):
pass
class NameAlreadyExists(Exception):
pass
class WalletError(Exception):
pass
class WalletNotSet(WalletError):
pass
class WalletNotInitialized(WalletError):
pass
class PortNotAvailable(OSError):
def __init__(self, port):
self.port = port
super().__init__("port not available: {}".format(port))
class OperationError(Exception):
def __init__(self, error):
super().__init__("error occurred during operation: {}".format(error))
class InvalidMessageExceedingSizeException(InvalidMessageException):
def __init__(self, expLen, actLen, *args, **kwargs):
ex_txt = 'Message len {} exceeded allowed limit of {}'.format(
actLen, expLen)
super().__init__(ex_txt, *args, **kwargs)
class RequestNackedException(Exception):
pass
class RequestRejectedException(Exception):
pass
class CommonSdkIOException(Exception):
pass
class PoolLedgerTimeoutException(Exception):
pass
class SuspiciousPrePrepare(Exception):
pass
class MissingProtocolVersionError(TypeError):
def __init__(self, message):
super().__init__(
message + 'Make sure that the latest LibIndy is '
'used and `set_protocol_version({})` is called.'
.format(CURRENT_PROTOCOL_VERSION))
class TaaAmlNotSetError(LogicError):
pass