-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.py
340 lines (237 loc) · 11 KB
/
errors.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
"""
Exceptions thrown by the Collections system.
"""
# mostly copied from https://github.com/kbase/sample_service
# TODO add to some sort of package?
from enum import Enum
from typing import Optional
class ErrorType(Enum):
"""
The type of an error, consisting of an error code and a brief string describing the type.
:ivar error_code: an integer error code.
:ivar error_type: a brief string describing the error type.
"""
AUTHENTICATION_FAILED = (10000, "Authentication failed") # noqa: E222 @IgnorePep8
""" A general authentication error. """
NO_TOKEN = (10010, "No authentication token") # noqa: E222 @IgnorePep8
""" No token was provided when required. """
INVALID_TOKEN = (10020, "Invalid token") # noqa: E222 @IgnorePep8
""" The token provided is not valid. """
INVALID_AUTH_HEADER = (10030, "Invalid authentication header") # noqa: E222 @IgnorePep8
""" The authentication header is not valid. """
UNAUTHORIZED = (20000, "Unauthorized") # noqa: E222 @IgnorePep8
""" The user is not authorized to perform the requested action. """
MISSING_PARAMETER = (30000, "Missing input parameter") # noqa: E222 @IgnorePep8
""" A required input parameter was not provided. """
ILLEGAL_PARAMETER = (30001, "Illegal input parameter") # noqa: E222 @IgnorePep8
""" An input parameter had an illegal value. """
REQUEST_VALIDATION_FAILED = (30010, "Request validation failed") # noqa: E222 @IgnorePep8
""" A request to a service failed validation of the request. """
NO_REGISTERED_DATA_PRODUCT = (30020, "No registered data product for collection") # noqa: E222 @IgnorePep8
""" There is no such data product registered with the collection. """
NO_SUCH_DATA_PRODUCT = (30030, "No such data product") # noqa: E222 @IgnorePep8
""" There is no such data product available in the service. """
NO_REGISTERED_MATCHER = (30040, "No registered matcher for collection") # noqa: E222 @IgnorePep8
""" There is no such matcher registered with the collection. """
NO_SUCH_MATCHER = (30050, "No such matcher") # noqa: E222 @IgnorePep8
""" There is no such matcher available in the service. """
INVALID_MATCH_STATE = (30060, "Invalid match state") # noqa: E222 @IgnorePep8
"""
The match state is invalid for the context - e.g. it's not complete, the user
is trying to use the match in the wrong collection or collection version, etc.
"""
INVALID_SELECTION_STATE = (30070, "Invalid selection state") # noqa: E222 @IgnorePep8
"""
The match selection is invalid for the context - e.g. it's not complete, the user
is trying to use the selection in the wrong collection or collection version, etc.
"""
MISSING_LINEAGE_ERROR = (30080, "Missing lineage error") # noqa: E222 @IgnorePep8
""" Data in a external data source is missing required lineage information. """
ILLEGAL_LINEAGE_ERROR = (30090, "Illegal lineage error") # noqa: E222 @IgnorePep8
""" Data in a external data source has illegal lineage information. """
LINEAGE_VERSION_ERROR = (30100, "Lineage version error") # noqa: E222 @IgnorePep8
""" Data in a external data source does not match the lineage version for the collection. """
NO_DATA_FOUND = (40000, "Requested data not found") # noqa: E222 @IgnorePep8
""" The requested data does not exist. """
NO_SUCH_COLLECTION = (40010, "No such collection") # noqa: E222 @IgnorePep8
""" The requested collection does not exist. """
NO_SUCH_COLLECTION_VERSION = (40020, "No such collection version") # noqa: E222 @IgnorePep8
""" The requested collection version does not exist. """
NO_SUCH_MATCH = (40030, "No such match") # noqa: E222 @IgnorePep8
""" The requested match does not exist. """
NO_SUCH_SELECTION = (40040, "No such selection") # noqa: E222 @IgnorePep8
""" The requested selection does not exist. """
COLLECTION_VERSION_EXISTS = (50000, "Collection version exists") # noqa: E222 @IgnorePep8
""" The requested collection version already exists. """
DATA_PERMISSION_ERROR = (60000, "Data permission error") # noqa: E222 @IgnorePep8
""" The user was not allowed to access data from a source outside the colletions service. """
UNSUPPORTED_OP = (100000, "Unsupported operation") # noqa: E222 @IgnorePep8
""" The requested operation is not supported. """
def __init__(self, error_code, error_type):
self.error_code = error_code
self.error_type = error_type
class CollectionError(Exception):
"""
The super class of all Collection related errors.
:ivar error_type: the error type of this error.
:ivar message: the message for this error.
"""
def __init__(self, error_type: ErrorType, message: Optional[str] = None):
'''
Create a Collection error.
:param error_type: the error type of this error.
:param message: an error message.
:raises TypeError: if error_type is None
'''
if not error_type: # don't use not_falsy here, causes circular import
raise TypeError('error_type cannot be None')
msg = message.strip() if message and message.strip() else None
super().__init__(msg)
self.error_type = error_type
self.message: Optional[str] = message
class AuthenticationError(CollectionError):
"""
Super class for authentication related errors.
"""
def __init__(self, error_type: ErrorType, message: Optional[str] = None):
super().__init__(error_type, message)
class MissingTokenError(AuthenticationError):
"""
An error thrown when a token is required but absent.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.NO_TOKEN, message)
class InvalidAuthHeaderError(AuthenticationError):
"""
An error thrown when an authorization header is invalid.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.INVALID_AUTH_HEADER, message)
class InvalidTokenError(AuthenticationError):
"""
An error thrown when a user's token is invalid.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.INVALID_TOKEN, message)
class UnauthorizedError(CollectionError):
"""
An error thrown when a user attempts a disallowed action.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.UNAUTHORIZED, message)
class MissingParameterError(CollectionError):
"""
An error thrown when a required parameter is missing.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.MISSING_PARAMETER, message)
class IllegalParameterError(CollectionError):
"""
An error thrown when a provided parameter is illegal.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.ILLEGAL_PARAMETER, message)
class NoRegisteredDataProductError(CollectionError):
"""
An error thrown when a requested data product is not registered with the collection.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.NO_REGISTERED_DATA_PRODUCT, message)
class NoSuchDataProductError(CollectionError):
"""
An error thrown when a requested data product does not exist.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.NO_SUCH_DATA_PRODUCT, message)
class NoRegisteredMatcherError(CollectionError):
"""
An error thrown when a requested matcher is not registered with a collection.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.NO_REGISTERED_MATCHER, message)
class NoSuchMatcherError(CollectionError):
"""
An error thrown when a requested matcher does not exist.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.NO_SUCH_MATCHER, message)
class InvalidMatchStateError(CollectionError):
"""
An error thrown when the state of a match is invalid.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.INVALID_MATCH_STATE, message)
class InvalidSelectionStateError(CollectionError):
"""
An error thrown when the state of a selection is invalid.
"""
def __init__(self, message: str = None):
super().__init__(ErrorType.INVALID_SELECTION_STATE, message)
class MissingLineageError(CollectionError):
"""
An error thrown when data outside the collections service is missing required lineage
information.
"""
def __init__(self, message: str):
super().__init__(ErrorType.MISSING_LINEAGE_ERROR, message)
class IllegalLineageError(CollectionError):
"""
An error thrown when data outside the collections service has illegal lineage information.
"""
def __init__(self, message: str):
super().__init__(ErrorType.ILLEGAL_LINEAGE_ERROR, message)
class LineageVersionError(CollectionError):
"""
An error thrown when data outside the collections service does not match the lineage version
in a collection.
"""
def __init__(self, message: str):
super().__init__(ErrorType.LINEAGE_VERSION_ERROR, message)
class NoDataError(CollectionError):
"""
An error thrown when expected data does not exist.
"""
def __init__(self, error_type: ErrorType, message: str):
super().__init__(error_type, message)
class NoDataFoundError(NoDataError):
"""
An generic error thrown when requested data does not exist.
"""
def __init__(self, message: str):
super().__init__(ErrorType.NO_DATA_FOUND, message)
class NoSuchCollectionError(NoDataError):
"""
An error thrown when a collection does not exist.
"""
def __init__(self, message: str):
super().__init__(ErrorType.NO_SUCH_COLLECTION, message)
class NoSuchCollectionVersionError(NoDataError):
"""
An error thrown when a collection version does not exist.
"""
def __init__(self, message: str):
super().__init__(ErrorType.NO_SUCH_COLLECTION_VERSION, message)
class NoSuchMatchError(NoDataError):
"""
An error thrown when a match does not exist.
"""
def __init__(self, message: str):
super().__init__(ErrorType.NO_SUCH_MATCH, message)
class NoSuchSelectionError(NoDataError):
"""
An error thrown when a selection does not exist.
"""
def __init__(self, message: str):
super().__init__(ErrorType.NO_SUCH_SELECTION, message)
class DataPermissionError(CollectionError):
"""
An error thrown when a user is not allowed access to data outside the collections service.
"""
def __init__(self, message: str):
super().__init__(ErrorType.DATA_PERMISSION_ERROR, message)
class CollectionVersionExistsError(CollectionError):
"""
An error thrown when a collection version already exists.
"""
def __init__(self, message: str):
super().__init__(ErrorType.COLLECTION_VERSION_EXISTS, message)