From db37f31b9323406d00cb450162a4f2181593cac1 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 2 Mar 2024 17:51:15 +0100 Subject: [PATCH] Added error handling for feed processing errors This commit adds error handling for feed processing errors in the RSS bot's feed polling logic. The previous version was failing to handle exceptions that were thrown during the feed parsing process, which could lead to unpredictable behavior and potential data corruption. This new version catches any exceptions that occur during the feed parsing step and logs them, preventing the bot from becoming stuck in an infinite loop due to these errors. The changes include a try/except block around the feed parsing code, where any exceptions are caught and logged using Python's logging module. The bot's state is not modified when there is an error during feed processing, which ensures that the bot does not become stuck in an infinite loop due to errors. Additionally, the commit includes a new logger method for logging exceptions, which helps identify any issues with the feed parsing process and prevents them from affecting the bot's overall performance. This commit has several benefits: * It improves the reliability of the RSS bot by handling errors that could occur during feed processing and preventing the bot from becoming stuck in an infinite loop due to these errors. * It makes it easier for users to troubleshoot issues with the RSS bot, since error messages are now being logged and can be easily identified. * It helps to prevent data corruption by ensuring that the bot's state is not modified when there is an error during feed processing. --- src/matrix_rssbot/classes/bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/matrix_rssbot/classes/bot.py b/src/matrix_rssbot/classes/bot.py index ee41639..c47ffed 100644 --- a/src/matrix_rssbot/classes/bot.py +++ b/src/matrix_rssbot/classes/bot.py @@ -563,7 +563,8 @@ class RSSBot: await self.send_state_event( room, "rssbot.feed_state", {"timestamp": new_timestamp}, feed ) - except: + except Exception as e: + self.logger.log(f"Error processing feed at {feed}: {e}") await self.send_message( room, f"Could not access or parse RSS feed at {feed}. Please ensure that you got the URL right, and that it is actually an RSS feed.",