loop-link 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
loop_link/errors.py ADDED
@@ -0,0 +1,279 @@
1
+ """Error types that loop_link raises.
2
+
3
+ All errors derive from :class:`LoopLinkError`, so a caller can catch every
4
+ loop_link error with one ``except`` clause.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass
10
+
11
+
12
+ class LoopLinkError(Exception):
13
+ """Base class for all loop_link errors."""
14
+
15
+
16
+ class NoViewerError(LoopLinkError):
17
+ """No viewer is available.
18
+
19
+ Parameters
20
+ ----------
21
+ message : str
22
+ The error text. The default text tells the user how to start a viewer.
23
+ """
24
+
25
+ def __init__(
26
+ self,
27
+ message: str = "No viewer is running. Start a viewer before you send objects.",
28
+ ) -> None:
29
+ super().__init__(message)
30
+
31
+
32
+ class TokenError(LoopLinkError):
33
+ """The access token is missing, wrong or expired.
34
+
35
+ Parameters
36
+ ----------
37
+ message : str
38
+ The error text. The default text tells the user how to get a new token.
39
+ """
40
+
41
+ def __init__(
42
+ self,
43
+ message: str = "The access token is not valid. Create a new token and try again.",
44
+ ) -> None:
45
+ super().__init__(message)
46
+
47
+
48
+ class BusyError(LoopLinkError):
49
+ """The viewer is busy with another request.
50
+
51
+ Parameters
52
+ ----------
53
+ message : str
54
+ The error text. The default text tells the user to wait and retry.
55
+ """
56
+
57
+ def __init__(
58
+ self,
59
+ message: str = "The viewer is busy. Wait a moment and try again.",
60
+ ) -> None:
61
+ super().__init__(message)
62
+
63
+
64
+ class InvalidInputError(LoopLinkError):
65
+ """An input value is not valid.
66
+
67
+ Parameters
68
+ ----------
69
+ message : str
70
+ The error text. The default text tells the user to check the input.
71
+ """
72
+
73
+ def __init__(
74
+ self,
75
+ message: str = "An input value is not valid. Check the input and try again.",
76
+ ) -> None:
77
+ super().__init__(message)
78
+
79
+
80
+ class ViewerClosedError(LoopLinkError):
81
+ """The viewer was closed.
82
+
83
+ Parameters
84
+ ----------
85
+ message : str
86
+ The error text. The default text tells the user to open the viewer again.
87
+ """
88
+
89
+ def __init__(
90
+ self,
91
+ message: str = "The viewer was closed. Open the viewer again and retry.",
92
+ ) -> None:
93
+ super().__init__(message)
94
+
95
+
96
+ class MissingFeatureError(LoopLinkError):
97
+ """A required feature is not available.
98
+
99
+ Parameters
100
+ ----------
101
+ feature : str
102
+ The name of the missing feature.
103
+
104
+ Attributes
105
+ ----------
106
+ feature : str
107
+ The name of the missing feature.
108
+ """
109
+
110
+ def __init__(self, feature: str) -> None:
111
+ self.feature = feature
112
+ super().__init__(
113
+ f"The feature '{feature}' is not available in this installation. "
114
+ f"Check that the '{feature}' feature is installed and enabled, then retry."
115
+ )
116
+
117
+
118
+ class ObjectTooLargeError(LoopLinkError):
119
+ """An object is larger than the allowed limit.
120
+
121
+ Parameters
122
+ ----------
123
+ object_id : str
124
+ The identifier of the object.
125
+ size : int
126
+ The size of the object.
127
+ limit : int
128
+ The largest size that is allowed.
129
+
130
+ Attributes
131
+ ----------
132
+ object_id : str
133
+ The identifier of the object.
134
+ size : int
135
+ The size of the object.
136
+ limit : int
137
+ The largest size that is allowed.
138
+ """
139
+
140
+ def __init__(self, object_id: str, size: int, limit: int) -> None:
141
+ self.object_id = object_id
142
+ self.size = size
143
+ self.limit = limit
144
+ super().__init__(
145
+ f"Object '{object_id}' is {size} units, which is larger than the limit of "
146
+ f"{limit} units. Reduce the size of the object or split it into smaller "
147
+ "objects, then try again."
148
+ )
149
+
150
+
151
+ class StaleRevisionError(LoopLinkError):
152
+ """An object is not at the revision that the caller expects.
153
+
154
+ Parameters
155
+ ----------
156
+ object_id : str
157
+ The identifier of the object.
158
+ revision : int, optional
159
+ The revision that the caller expected.
160
+
161
+ Attributes
162
+ ----------
163
+ object_id : str
164
+ The identifier of the object.
165
+ revision : int, optional
166
+ The revision that the caller expected.
167
+ """
168
+
169
+ def __init__(self, object_id: str, revision: int | None = None) -> None:
170
+ self.object_id = object_id
171
+ self.revision = revision
172
+ super().__init__(
173
+ f"The object '{object_id}' is not at that revision in the viewer. "
174
+ "Read the selection or fetch the object again, then try again."
175
+ )
176
+
177
+
178
+ class CancelledError(LoopLinkError):
179
+ """The request was cancelled.
180
+
181
+ Parameters
182
+ ----------
183
+ message : str
184
+ The error text. The default text says that the request was cancelled.
185
+ """
186
+
187
+ def __init__(self, message: str = "The request was cancelled.") -> None:
188
+ super().__init__(message)
189
+
190
+
191
+ class UnsupportedObjectError(LoopLinkError):
192
+ """The object type cannot be fetched by loop_link.
193
+
194
+ Parameters
195
+ ----------
196
+ object_id : str
197
+ The identifier of the object.
198
+ object_type : str
199
+ The type of the object.
200
+
201
+ Attributes
202
+ ----------
203
+ object_id : str
204
+ The identifier of the object.
205
+ object_type : str
206
+ The type of the object.
207
+ """
208
+
209
+ def __init__(self, object_id: str, object_type: str) -> None:
210
+ self.object_id = object_id
211
+ self.object_type = object_type
212
+ super().__init__(
213
+ f"The object '{object_id}' has the type '{object_type}'. loop_link can fetch "
214
+ "Points, Curve, Surface, BlockModel, TetraMesh and Drillhole objects only."
215
+ )
216
+
217
+
218
+ @dataclass(frozen=True)
219
+ class Refusal:
220
+ """A reason why the viewer refused one object.
221
+
222
+ Parameters
223
+ ----------
224
+ object_id : str
225
+ The identifier of the refused object.
226
+ code : str
227
+ A short code that names the reason.
228
+ message : str
229
+ A message that explains the reason.
230
+ """
231
+
232
+ object_id: str
233
+ code: str
234
+ message: str
235
+
236
+
237
+ class ViewerRefusedError(LoopLinkError):
238
+ """The viewer refused one or more objects.
239
+
240
+ Parameters
241
+ ----------
242
+ refusals : list of Refusal
243
+ The refusals, one for each refused object.
244
+
245
+ Attributes
246
+ ----------
247
+ refusals : list of Refusal
248
+ The refusals, one for each refused object.
249
+ """
250
+
251
+ def __init__(self, refusals: list[Refusal]) -> None:
252
+ self.refusals = refusals
253
+ count = len(refusals)
254
+ super().__init__(
255
+ f"The viewer refused {count} object(s). Read the code and message of each "
256
+ "refusal, fix those objects, and try again."
257
+ )
258
+
259
+
260
+ class MissingExtraError(LoopLinkError):
261
+ """An optional extra package is not installed.
262
+
263
+ Parameters
264
+ ----------
265
+ extra : str
266
+ The name of the extra.
267
+
268
+ Attributes
269
+ ----------
270
+ extra : str
271
+ The name of the extra.
272
+ """
273
+
274
+ def __init__(self, extra: str) -> None:
275
+ self.extra = extra
276
+ super().__init__(
277
+ f"The optional '{extra}' part of loop-link is not installed. "
278
+ f"Run: pip install loop-link[{extra}]"
279
+ )