11
11
12
12
from pyppeteer import helper
13
13
from pyppeteer .connection import Session
14
+ from pyppeteer .errors import BrowserError , NetworkError , PageError
14
15
from pyppeteer .input import Mouse
15
16
from pyppeteer .element_handle import ElementHandle
16
17
@@ -71,7 +72,7 @@ def _onFrameNavigated(self, framePayload: dict) -> None:
71
72
else :
72
73
self ._frames .get (framePayload .get ('id' , '' ))
73
74
if not (isMainFrame or frame ):
74
- raise Exception ('We either navigate top level or have old version '
75
+ raise PageError ('We either navigate top level or have old version '
75
76
'of the navigated frame' )
76
77
77
78
# Detach all child frames first.
@@ -180,10 +181,11 @@ async def _rawEvaluate(self, pageFunction: str, *args: str) -> dict:
180
181
exceptionDetails = obj .get ('exceptionDetails' , dict ())
181
182
remoteObject = obj .get ('result' , dict ())
182
183
if exceptionDetails :
183
- raise Exception ('Evaluation failed: ' +
184
- helper .getExceptionMessage (exceptionDetails ) +
185
- f'\n pageFunction:\n { pageFunction } '
186
- )
184
+ raise BrowserError (
185
+ 'Evaluation failed: ' +
186
+ helper .getExceptionMessage (exceptionDetails ) +
187
+ f'\n pageFunction:\n { pageFunction } '
188
+ )
187
189
return remoteObject
188
190
189
191
@property
@@ -243,7 +245,7 @@ def waitFor(self, selectorOrFunctionOrTimeout: Union[str, int, float],
243
245
return fut
244
246
if not isinstance (selectorOrFunctionOrTimeout , str ):
245
247
fut = asyncio .get_event_loop ().create_future ()
246
- fut .set_exception (Exception (
248
+ fut .set_exception (TypeError (
247
249
'Unsupported target type: ' +
248
250
str (type (selectorOrFunctionOrTimeout ))
249
251
))
@@ -303,7 +305,7 @@ def _navigated(self, framePayload: dict) -> None:
303
305
def _detach (self ) -> None :
304
306
for waitTask in self ._waitTasks :
305
307
waitTask .terminate (
306
- Exception ('waitForSelector failed: frame got detached.' ))
308
+ PageError ('waitForSelector failed: frame got detached.' ))
307
309
self ._detached = True
308
310
if self ._parentFrame :
309
311
self ._parentFrame ._childFrames .remove (self )
@@ -319,13 +321,13 @@ def __init__(self, frame: Frame, predicateBody: str,
319
321
super ().__init__ ()
320
322
if isinstance (polling , str ):
321
323
if polling not in ('raf' , 'mutation' ):
322
- raise Exception ('Unknown polling option: ' + polling )
324
+ raise ValueError ('Unknown polling option: ' + polling )
323
325
elif isinstance (polling , (int , float )):
324
326
if polling <= 0 :
325
- raise Exception (
327
+ raise ValueError (
326
328
f'Cannot poll with non-positive interval: { polling } ' )
327
329
else :
328
- raise Exception ('Unknown polling options: ' + str (polling ))
330
+ raise ValueError ('Unknown polling options: ' + str (polling ))
329
331
330
332
self ._frame : Frame = frame
331
333
self ._pageScript : str = helper .evaluationString (
@@ -339,7 +341,7 @@ def __init__(self, frame: Frame, predicateBody: str,
339
341
self ._timeoutTimer = loop .call_later (
340
342
timeout / 1000 ,
341
343
lambda : self .terminate (
342
- Exception (f'waiting failed: timeout { timeout } ms exceeded' )
344
+ NetworkError (f'waiting failed: timeout { timeout } ms exceeded' )
343
345
)
344
346
)
345
347
asyncio .ensure_future (self .rerun ())
0 commit comments