@@ -27,7 +27,11 @@ class JavascriptError(RuntimeError): # TODO(AJP): process better
2727
2828### Error definitions ###
2929class KaleidoError (Exception ):
30- """An error to interpret errors from Kaleido's JS side."""
30+ """
31+ An error to interpret errors from Kaleido's JS side.
32+
33+ This is not for all js errors, just kaleido_scopes.js errors.
34+ """
3135
3236 def __init__ (self , code , message ):
3337 """
@@ -47,7 +51,7 @@ def __str__(self):
4751 return f"Error { self ._code } : { self ._message } "
4852
4953
50- def _check_error_ret (result ):
54+ def _get_error (result ):
5155 """Check browser response for errors. Helper function."""
5256 if "error" in result :
5357 return DevtoolsProtocolError (result )
@@ -56,8 +60,8 @@ def _check_error_ret(result):
5660 return None
5761
5862
59- def _check_error (result ):
60- e = _check_error_ret (result )
63+ def _raise_error (result ):
64+ e = _get_error (result )
6165 if e :
6266 raise e
6367
@@ -76,7 +80,7 @@ class _KaleidoTab:
7680 """
7781 A Kaleido tab is a wrapped choreographer tab providing the functions we need.
7882
79- The choreographer tab can be access through the `self.tab` attribute.
83+ The choreographer tab can be accessed through the `self.tab` attribute.
8084 """
8185
8286 tab : choreo .Tab
@@ -124,12 +128,12 @@ async def navigate(self, url: str | Path = ""):
124128 page_ready = tab .subscribe_once ("Page.loadEventFired" )
125129
126130 _logger .debug2 (f"Calling Page.navigate on { tab } " )
127- _check_error (await tab .send_command ("Page.navigate" , params = {"url" : url }))
131+ _raise_error (await tab .send_command ("Page.navigate" , params = {"url" : url }))
128132 # Must enable after navigating.
129133 _logger .debug2 (f"Calling Page.enable on { tab } " )
130- _check_error (await tab .send_command ("Page.enable" ))
134+ _raise_error (await tab .send_command ("Page.enable" ))
131135 _logger .debug2 (f"Calling Runtime.enable on { tab } " )
132- _check_error (await tab .send_command ("Runtime.enable" ))
136+ _raise_error (await tab .send_command ("Runtime.enable" ))
133137
134138 await javascript_ready
135139 self ._current_js_id = (
@@ -159,7 +163,7 @@ async def reload(self):
159163 _logger .debug2 ("Clearing an old Page.loadEventFired" )
160164 is_loaded = tab .subscribe_once ("Page.loadEventFired" )
161165 _logger .debug2 (f"Calling Page.reload on { tab } " )
162- _check_error (await tab .send_command ("Page.reload" ))
166+ _raise_error (await tab .send_command ("Page.reload" ))
163167 await javascript_ready
164168 self ._current_js_id = (
165169 javascript_ready .result ()
@@ -196,7 +200,7 @@ async def console_print(self, message: str) -> None:
196200 _logger .debug ("Calling js function" )
197201 result = await self .tab .send_command ("Runtime.callFunctionOn" , params = params )
198202 _logger .debug (f"Sent javascript got result: { result } " )
199- _check_error (result )
203+ _raise_error (result )
200204
201205 def _finish_profile (self , profile , state , error = None ):
202206 _logger .debug ("Finishing profile" )
@@ -308,7 +312,7 @@ async def _calc_fig( # noqa: C901, PLR0912, complexity, branches
308312 if profile :
309313 profile ["state" ] = "SENT"
310314 _logger .info (f"Sent big command for { full_path .name } ." )
311- e = _check_error_ret (result )
315+ e = _get_error (result )
312316 if e :
313317 if profiler is not None :
314318 self ._finish_profile (profile , "ERROR" , e )
@@ -366,7 +370,7 @@ async def _img_from_response(self, response):
366370 "Page.printToPDF" ,
367371 params = pdf_params ,
368372 )
369- e = _check_error_ret (pdf_response )
373+ e = _get_error (pdf_response )
370374 if e :
371375 return e
372376 img = pdf_response .get ("result" ).get ("data" )
0 commit comments