-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptions.py
More file actions
218 lines (150 loc) · 4.86 KB
/
exceptions.py
File metadata and controls
218 lines (150 loc) · 4.86 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
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
## Expected errors:
from . import opsqueue_internal
from typing import Optional
class SubmissionFailedError(Exception):
__slots__ = ["submission", "chunk", "failure"]
"""
Raised when a submission failed,
that is: One of the chunks of this submission
failed more than `retry_count` times,
(default: 10, configurable when Opsqueue is started).
This means that part of the submission is missing and therefore
it can never be 'completed' anymore.
"""
def __init__(
self,
submission: opsqueue_internal.SubmissionFailed,
chunk: opsqueue_internal.ChunkFailed,
):
super().__init__()
self.submission = submission
self.chunk = chunk
self.failure = self.chunk.failure
def __str__(self) -> str:
return f"""
Submission {self.submission.id} failed because chunk {self.chunk.chunk_index} kept failing.
Failure reason:
{self.failure}
"""
def __repr__(self) -> str:
return str(self)
class SubmissionNotCancellableError(Exception):
"""Raised when a submission could not be cancelled due to already being
completed, failed or cancelled.
"""
__slots__ = ["submission", "chunk"]
def __init__(
self,
submission: opsqueue_internal.SubmissionNotCancellable,
chunk: Optional[opsqueue_internal.ChunkFailed] = None,
):
super().__init__()
self.submission = submission
self.chunk = chunk
def __str__(self) -> str:
chunk_str = f"\n{self.chunk}"
return f"""
Submission {self.submission.submission.id} was not cancelled because:
{self.submission}
{"" if self.chunk is None else chunk_str}
"""
def __repr__(self) -> str:
return str(self)
## Usage errors:
class IncorrectUsageError(TypeError):
"""
Base exception class for all different ways
Python code might be calling the Opsqueue's client library
incorrectly.
"""
pass
class TryFromIntError(IncorrectUsageError):
"""
Raised when code expects a particular subset of integers,
but an invalid integer is passed (such as passing a negative value
to a place expecting zero or positive).
"""
pass
class ChunkNotFoundError(IncorrectUsageError):
"""
Raised when a method is used to look up information about a chunk
but the chunk doesn't exist within the Opsqueue.
"""
pass
class SubmissionNotFoundError(IncorrectUsageError):
"""
Raised when a method is used to look up information about a submission
but the submission doesn't exist within the Opsqueue.
"""
__slots__ = ["submission_id"]
def __init__(
self,
submission_id: int,
):
super().__init__()
self.submission_id = submission_id
def __str__(self) -> str:
return f"Submission {self.submission_id} could not be found"
def __repr__(self) -> str:
return str(self)
class ChunkCountIsZeroError(IncorrectUsageError):
"""
Raised when making an empty submission.
TODO it is likely that empty submissions should not be a user error
but rather be handled transparently by Opsqueue.
"""
pass
class NewObjectStoreClientError(IncorrectUsageError):
"""
Raised when incorrect settings were used when attempting to initialize
the object store connection.
"""
pass
class SubmissionNotCompletedYetError(IncorrectUsageError):
"""
Raised when a method attempts to look up info
from a completed submission but the submission
is not completed yet.
"""
pass
# Internal errors:
class OpsqueueInternalError(Exception):
"""
Base type for all internal exceptions
"""
pass
class UnexpectedOpsqueueConsumerServerResponseError(OpsqueueInternalError):
"""
Handled when the consumer client receives as response
to a sync method something other than what it had expected.
This may indicate that the client and server versions are not matching,
or that there is an implementatoin error in the Opsqueue code.
"""
pass
class ChunkRetrievalError(OpsqueueInternalError):
"""
Raised when there is a problem when fetching a chunk from the object store.
"""
pass
class ChunksStorageError(OpsqueueInternalError):
"""
Raised when there is a problem when the producer
is attempting to store all its chunks into the object store.
"""
pass
class ChunkStorageError(OpsqueueInternalError):
"""
Raised when there is a problem when a consumer
is storing a chunk to the object store.
"""
pass
class InternalConsumerClientError(OpsqueueInternalError):
"""
Raised for any othre kind of Consumer client exception
"""
pass
class InternalProducerClientError(OpsqueueInternalError):
"""
Raised for any othre kind of Producer client exception
"""
pass