From e051b29bf2bc9cd2a671604fd2221ac0a8c5a76e Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 5 Jan 2024 11:29:48 +0100 Subject: [PATCH] Browser Steps - General error handling improvements (#2083) --- changedetectionio/content_fetcher.py | 14 ++++++++------ changedetectionio/update_worker.py | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/changedetectionio/content_fetcher.py b/changedetectionio/content_fetcher.py index e9477270..4c8a382c 100644 --- a/changedetectionio/content_fetcher.py +++ b/changedetectionio/content_fetcher.py @@ -43,9 +43,11 @@ class JSActionExceptions(Exception): return -class BrowserStepsStepTimout(Exception): - def __init__(self, step_n): +class BrowserStepsStepException(Exception): + def __init__(self, step_n, original_e): self.step_n = step_n + self.original_e = original_e + print(f"Browser Steps exception at step {self.step_n}", str(original_e)) return @@ -173,7 +175,7 @@ class Fetcher(): def iterate_browser_steps(self): from changedetectionio.blueprint.browser_steps.browser_steps import steppable_browser_interface - from playwright._impl._errors import TimeoutError + from playwright._impl._errors import TimeoutError, Error from jinja2 import Environment jinja2_env = Environment(extensions=['jinja2_time.TimeExtension']) @@ -203,10 +205,10 @@ class Fetcher(): optional_value=optional_value) self.screenshot_step(step_n) self.save_step_html(step_n) - except TimeoutError as e: - print(str(e)) + + except (Error, TimeoutError) as e: # Stop processing here - raise BrowserStepsStepTimout(step_n=step_n) + raise BrowserStepsStepException(step_n=step_n, original_e=e) # It's always good to reset these def delete_browser_steps_screenshots(self): diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index b94913fa..ac759e2f 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -354,20 +354,32 @@ class update_worker(threading.Thread): changed_detected = False self.datastore.update_watch(uuid=uuid, update_obj={'last_error': False}) - except content_fetcher.BrowserStepsStepTimout as e: + except content_fetcher.BrowserStepsStepException as e: if not self.datastore.data['watching'].get(uuid): continue error_step = e.step_n + 1 - err_text = f"Warning, browser step at position {error_step} could not run, target not found, check the watch, add a delay if necessary, view Browser Steps to see screenshot at that step" + from playwright._impl._errors import TimeoutError, Error + + # Generally enough info for TimeoutError (couldnt locate the element after default seconds) + err_text = f"Browser step at position {error_step} could not run, check the watch, add a delay if necessary, view Browser Steps to see screenshot at that step." + + if e.original_e.name == "TimeoutError": + # Just the first line is enough, the rest is the stack trace + err_text += " Could not find the target." + else: + # Other Error, more info is good. + err_text += " " + str(e.original_e).splitlines()[0] + + print(f"BrowserSteps exception at step {error_step}", str(e.original_e)) + self.datastore.update_watch(uuid=uuid, update_obj={'last_error': err_text, 'browser_steps_last_error_step': error_step } ) - if self.datastore.data['watching'][uuid].get('filter_failure_notification_send', False): c = self.datastore.data['watching'][uuid].get('consecutive_filter_failures', 5) c += 1