diff --git a/src/bot_data/db_context.py b/src/bot_data/db_context.py index 0e066720..8ad5414c 100644 --- a/src/bot_data/db_context.py +++ b/src/bot_data/db_context.py @@ -6,9 +6,9 @@ from cpl_core.logging import LoggerABC class DBContext(DatabaseContext): def __init__(self, logger: LoggerABC): - + self._logger = logger - + DatabaseContext.__init__(self) def connect(self, database_settings: DatabaseSettings): @@ -20,7 +20,7 @@ class DBContext(DatabaseContext): self._logger.info(__name__, "Connected to database") except Exception as e: self._logger.fatal(__name__, "Connecting to database failed", e) - + def save_changes(self): try: self._logger.trace(__name__, "Save changes") @@ -28,6 +28,10 @@ class DBContext(DatabaseContext): self._logger.debug(__name__, "Saved changes") except Exception as e: self._logger.error(__name__, "Saving changes failed", e) - + def select(self, statement: str) -> list[tuple]: - return super(DBContext, self).select(statement) + try: + return super(DBContext, self).select(statement) + except Exception as e: + self._logger.error(__name__, f'Database error caused by {statement}', e) + return []