e-dreyer / mastoBot

A generic bot that allows anyone to create group bots on Mastodon.
GNU General Public License v3.0
3 stars 0 forks source link

Improved exception handling required #4

Open e-dreyer opened 1 year ago

e-dreyer commented 1 year ago

Problem

Currently MastoBot implements a wrapper and decorator function which allows for the handling of exceptions in most functions making API calls through Mastodon.py. This however is not the best solution. Exceptions are still able to slip through and there is actually no handling of exceptions and they are rather logged.

It should be investigated how a queue system for API calls can be created and operations then postponed until a connection error or rate limiting possibly sort itself out.

Related issues

Current solution

def handleMastodonExceptions(func) -> Callable:
    def wrapper(self, *args, **kwargs):
        try:
            result = func(self, *args, **kwargs)
            return result
        except MastodonServerError as e:
            logging.critical(f"MastodonServerError: {e}")
        except MastodonIllegalArgumentError as e:
            logging.critical(f"MastodonIllegalArgumentError: {e}")
        except MastodonFileNotFoundError as e:
            logging.critical(f"MastodonFileNotFoundError: {e}")
        except MastodonNetworkError as e:
            logging.critical(f"MastodonNetworkError: {e}")
        except MastodonAPIError as e:
            logging.critical(f"MastodonAPIError: {e}")
        except MastodonMalformedEventError as e:
            logging.critical(f"MastodonMalformedEventError: {e}")
        except MastodonRatelimitError as e:
            logging.critical(f"MastodonRatelimitError: {e}")
        except MastodonVersionError as e:
            logging.critical(f"MastodonVersionError: {e}")
        except Exception as e:
            logging.critical(f"Error in function {func.__name__}")
            logging.critical(e)
            raise e
    return wrapper
e-dreyer commented 1 year ago

As proposed in #6, a data storage system would help a lot with systems like this. Because pending notifications should persist through a restart or crash. How to implement such a storage system is the question.

Even by implementing some caching system, would require a persistent store. Doing so, would complicate the Docker setup. Ideally we want the user to be able to completely define their own Docker setup and not require extra containers or images such as Redis.