-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathexceptions.py
More file actions
349 lines (178 loc) · 9.59 KB
/
exceptions.py
File metadata and controls
349 lines (178 loc) · 9.59 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
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
"""
Pydoll Exception Classes
This module contains all exception classes used throughout the Pydoll library,
organized into logical categories based on their function and usage patterns.
Each category uses a base class to provide common functionality for related exceptions.
"""
class PydollException(Exception):
"""Base class for all Pydoll exceptions."""
message = 'An error occurred in Pydoll'
def __init__(self, message: str = ''):
self.message = message or self.message
def __str__(self):
return self.message
class ConnectionException(PydollException):
"""Base class for exceptions related to browser connection."""
message = 'A connection error occurred'
class ConnectionFailed(ConnectionException):
"""Raised when connection to the browser cannot be established."""
message = 'Failed to connect to the browser'
class ReconnectionFailed(ConnectionException):
"""Raised when an attempt to reconnect to the browser fails."""
message = 'Failed to reconnect to the browser'
class WebSocketConnectionClosed(ConnectionException):
"""Raised when the WebSocket connection to the browser is closed unexpectedly."""
message = 'The WebSocket connection is closed'
class NetworkError(ConnectionException):
"""Raised when a general network error occurs during browser communication."""
message = 'A network error occurred'
class BrowserException(PydollException):
"""Base class for exceptions related to browser process management."""
message = 'A browser error occurred'
class BrowserNotRunning(BrowserException):
"""Raised when attempting to interact with a browser that is not running."""
message = 'The browser is not running'
class FailedToStartBrowser(BrowserException):
"""Raised when the browser process cannot be started."""
message = 'Failed to start the browser'
class UnsupportedOS(BrowserException):
"""Raised when attempting to run on an unsupported operating system."""
message = 'Unsupported OS'
class NoValidTabFound(BrowserException):
"""Raised when no valid browser tab can be found or created."""
message = 'No valid attached tab found'
class InvalidConnectionPort(BrowserException):
"""Raised when an invalid (non-positive) connection port is provided."""
message = 'Connection port must be a positive integer'
class InvalidWebSocketAddress(BrowserException):
"""Raised when an invalid WebSocket address is provided or required but missing."""
message = 'Invalid WebSocket address'
class MissingTargetOrWebSocket(BrowserException):
"""Raised when a Tab has neither target ID nor WebSocket address available."""
message = 'Tab has no target ID or WebSocket address'
class ProtocolException(PydollException):
"""Base class for exceptions related to CDP protocol communication."""
message = 'A protocol error occurred'
class TopLevelTargetRequired(ProtocolException):
"""Raised when a command can only be executed on top-level targets."""
message = 'Command can only be executed on top-level targets.'
class InvalidCommand(ProtocolException):
"""Raised when an invalid command is sent to the browser."""
message = 'The command provided is invalid'
class InvalidResponse(ProtocolException):
"""Raised when an invalid response is received from the browser."""
message = 'The response received is invalid'
class ResendCommandFailed(ProtocolException):
"""Raised when an attempt to resend a failed command fails."""
message = 'Failed to resend the command'
class CommandExecutionTimeout(ProtocolException):
"""Raised when a command execution times out."""
message = 'The command execution timed out'
class InvalidCallback(ProtocolException):
"""Raised when an invalid callback is provided for an event."""
message = 'The callback provided is invalid'
class EventNotSupported(ProtocolException):
"""Raised when an attempt is made to subscribe to an unsupported event."""
message = 'The event is not supported'
class ElementException(PydollException):
"""Base class for exceptions related to element interactions."""
message = 'An element interaction error occurred'
class ElementNotFound(ElementException):
"""Raised when an element cannot be found in the DOM."""
message = 'The specified element was not found'
class ElementNotVisible(ElementException):
"""Raised when attempting to interact with an element that is not visible."""
message = 'The element is not visible'
class ElementNotInteractable(ElementException):
"""Raised when attempting to interact with an element that cannot receive interaction."""
message = 'The element is not interactable'
class ClickIntercepted(ElementException):
"""Raised when a click operation is intercepted by another element."""
message = 'The click was intercepted'
class ElementNotAFileInput(ElementException):
"""Raised when attempting to use file input methods on a non-file input element."""
message = 'The element is not a file input'
class ShadowRootNotFound(ElementException):
"""Raised when an element does not have an attached shadow root."""
message = 'No shadow root attached to this element'
class TimeoutException(PydollException):
"""Base class for exceptions related to timeouts."""
message = 'A timeout occurred'
class PageLoadTimeout(TimeoutException):
"""Raised when a page load operation times out."""
message = 'Page load timed out'
class WaitElementTimeout(TimeoutException):
"""Raised when waiting for an element times out."""
message = 'Timed out waiting for element to appear'
class DownloadTimeout(TimeoutException):
"""Raised when waiting for a file download to complete times out."""
message = 'Timed out waiting for download to complete'
class ConfigurationException(PydollException):
"""Base class for exceptions related to configuration and options."""
message = 'A configuration error occurred'
class InvalidOptionsObject(ConfigurationException):
"""Raised when an invalid options object is provided."""
message = 'The options object provided is invalid'
class InvalidBrowserPath(ConfigurationException):
"""Raised when an invalid browser executable path is provided."""
message = 'The browser path provided is invalid'
class ArgumentAlreadyExistsInOptions(ConfigurationException):
"""Raised when attempting to add a duplicate argument to browser options."""
message = 'The argument already exists in the options'
class ArgumentNotFoundInOptions(ConfigurationException):
"""Raised when attempting to remove an argument that does not exist in browser options."""
message = 'The argument does not exist in the options'
class InvalidFileExtension(ConfigurationException):
"""Raised when an unsupported file extension is provided."""
message = 'The file extension provided is not supported'
class InvalidTabInitialization(ConfigurationException):
"""Raised when creating a Tab without connection_port, target_id or ws_address."""
message = 'Either connection_port, target_id, or ws_address must be provided'
class MissingScreenshotPath(ConfigurationException):
"""Raised when take_screenshot is called without path and not returning base64."""
message = 'path is required when as_base64 is False'
class DialogException(PydollException):
"""Base class for exceptions related to browser dialogs."""
message = 'A dialog error occurred'
class NoDialogPresent(DialogException):
"""Raised when attempting to interact with a dialog that doesn't exist."""
message = 'No dialog present on the page'
class NotAnIFrame(PydollException):
"""Raised when an element is not an iframe."""
message = 'The element is not an iframe'
class InvalidIFrame(PydollException):
"""Raised when an iframe is not valid."""
message = 'The iframe is not valid'
class IFrameNotFound(PydollException):
"""Raised when an iframe is not found."""
message = 'The iframe was not found'
class NetworkEventsNotEnabled(PydollException):
"""Raised when network events are not enabled."""
message = 'Network events not enabled'
class RequestException(PydollException):
"""Base class for exceptions related to HTTP requests."""
message = 'An HTTP request error occurred'
class HTTPError(RequestException):
"""Exception raised for HTTP error responses (4xx and 5xx status codes)."""
message = 'An HTTP error occurred'
class HarRecordingError(RequestException):
"""Raised when HAR recording fails."""
message = 'HAR recording error occurred'
class ScriptException(PydollException):
"""Base class for exceptions related to JavaScript execution."""
message = 'A script execution error occurred'
class InvalidScriptWithElement(ScriptException):
"""Raised when a script contains 'argument' but no element is provided."""
message = 'Script contains "argument" but no element was provided'
class WrongPrefsDict(PydollException):
"""Raised when the prefs dict provided contains the 'prefs' key"""
message = 'The dict can not contain "prefs" key, provide only the prefs options'
class InvalidPreferencePath(PydollException):
"""Raised when a provided preference path is invalid (segment doesn't exist)."""
message = 'Invalid preference path'
class InvalidPreferenceValue(PydollException):
"""Invalid value for a preference (incompatible type)"""
message = 'Invalid preference value'
class ElementPreconditionError(ElementException):
"""Raised when invalid or missing preconditions are provided for element operations."""
message = 'Invalid element preconditions'