From 8de4719701b8e42f3c1af04d6befb74402d951f9 Mon Sep 17 00:00:00 2001 From: boyska Date: Mon, 17 Jan 2022 00:03:08 +0100 Subject: [PATCH] better handle badly-written DBs --- larigira/db.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/larigira/db.py b/larigira/db.py index 0c1da6e..13aacf0 100644 --- a/larigira/db.py +++ b/larigira/db.py @@ -42,11 +42,18 @@ class EventModel(object): if not name.isalpha(): self.log.warning("%s db file name is not valid: it must be alphabetic only", str(db_file.name)) continue - self._dbs[name] = TinyDB( - str(db_file), - storage=ReadOnlyMiddleware(JSONStorage), - default_table='actions' - ) + try: + self._dbs[name] = TinyDB( + str(db_file), + storage=ReadOnlyMiddleware(JSONStorage), + default_table='actions' + ) + except ReadOnlyException: + # TinyDB adds the default_table if it is not present at read time. + # This should not happen at all for a ReadOnlyMiddleware db, but at least we can notice it and + # properly signal this to the user. + self.log.error("Could not load db %s: 'actions' table is missing", db_file.name) + continue self.log.debug('Loaded %d databases: %s', len(self._dbs), ','.join(self._dbs.keys()))