From 7fac92652c350ae5a49c1ea455d86a243e8571a1 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Sun, 28 Nov 2021 02:14:35 -0500 Subject: [PATCH] catch webhook errors --- modules/builder.py | 20 +++++++++++++------- modules/config.py | 15 ++++++++++++--- modules/library.py | 3 --- plex_meta_manager.py | 6 +++++- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/modules/builder.py b/modules/builder.py index 7b887c82..2d9c55d8 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -2123,13 +2123,19 @@ class CollectionBuilder: (self.details["collection_removal_webhooks"] and len(self.notification_removals) > 0) ): self.obj.reload() - self.library.Webhooks.collection_hooks( - self.details["collection_creation_webhooks"] + self.details["collection_addition_webhooks"] + self.details["collection_removal_webhooks"], - self.obj, - created=self.created, - additions=self.notification_additions, - removals=self.notification_removals - ) + try: + self.library.Webhooks.collection_hooks( + self.details["collection_creation_webhooks"] + + self.details["collection_addition_webhooks"] + + self.details["collection_removal_webhooks"], + self.obj, + created=self.created, + additions=self.notification_additions, + removals=self.notification_removals + ) + except Failed as e: + util.print_stacktrace() + logger.error(f"Webhooks Error: {e}") def run_collections_again(self): self.obj = self.library.get_collection(self.name) diff --git a/modules/config.py b/modules/config.py index 627e04b2..b04fffc5 100644 --- a/modules/config.py +++ b/modules/config.py @@ -125,7 +125,8 @@ class Config: else: endline = "" yaml.round_trip_dump(loaded_config, open(self.config_path, "w"), indent=None, block_seq_indent=2) elif data[attribute] is None: - if default_is_none is True: return None + if default_is_none and var_type == "list": return [] + elif default_is_none: return None else: message = f"{text} is blank" elif var_type == "url": if data[attribute].endswith(("\\", "/")): return data[attribute][:-1] @@ -229,7 +230,11 @@ class Config: logger.warning("notifiarr attribute not found") self.Webhooks = Webhooks(self, self.webhooks, notifiarr=self.NotifiarrFactory) - self.Webhooks.start_time_hooks(self.run_start_time) + try: + self.Webhooks.start_time_hooks(self.run_start_time) + except Failed as e: + util.print_stacktrace() + logger.error(f"Webhooks Error: {e}") self.errors = [] @@ -604,7 +609,11 @@ class Config: def notify(self, text, library=None, collection=None, critical=True): for error in util.get_list(text, split=False): - self.Webhooks.error_hooks(error, library=library, collection=collection, critical=critical) + try: + self.Webhooks.error_hooks(error, library=library, collection=collection, critical=critical) + except Failed as e: + util.print_stacktrace() + logger.error(f"Webhooks Error: {e}") def get_html(self, url, headers=None, params=None): return html.fromstring(self.get(url, headers=headers, params=params).content) diff --git a/modules/library.py b/modules/library.py index 9e063323..4f3854a5 100644 --- a/modules/library.py +++ b/modules/library.py @@ -183,9 +183,6 @@ class Library(ABC): self.config.Cache.update_image_map(item.ratingKey, f"{self.image_table_name}_backgrounds", item.art, background.compare) def notify(self, text, collection=None, critical=True): - for error in util.get_list(text, split=False): - self.Webhooks.error_hooks(error, library=self, collection=collection, critical=critical) - self.config.notify(text, library=self, collection=collection, critical=critical) @abstractmethod diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 2c94e13e..f6e73550 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -154,7 +154,11 @@ def start(attrs): logger.info("") run_time = str(datetime.now() - start_time).split('.')[0] if config: - config.Webhooks.end_time_hooks(start_time, run_time, stats) + try: + config.Webhooks.end_time_hooks(start_time, run_time, stats) + except Failed as e: + util.print_stacktrace() + logger.error(f"Webhooks Error: {e}") util.separator(f"Finished {start_type}Run\nRun Time: {run_time}") logger.removeHandler(file_handler)