feat: add useful error message for when the store manager cant be initialized

Refs: OPS-83
This commit is contained in:
Christoph J. Scherr 2025-03-23 13:58:06 +01:00
parent 2c7394edfa
commit 45519743bd
No known key found for this signature in database
GPG key ID: 9EB784BB202BB7BB

View file

@ -12,13 +12,25 @@ from senju.haiku import Haiku
DEFAULT_DB_PATH: Path = Path("/var/lib/senju.json")
class BadStoreManagerFileError(Exception):
def __init__(self, msg: str, * args: object) -> None:
self.msg = msg
super().__init__(*args)
def __str__(self) -> str:
return f"Store file is corrupted: {self.msg}"
class StoreManager:
__slots__ = "_db", "logger"
_db: TinyDB
logger: Logger
def __init__(self, path_to_db: Path = DEFAULT_DB_PATH) -> None:
self._db = TinyDB(path_to_db)
try:
self._db = TinyDB(path_to_db)
except Exception as e:
raise BadStoreManagerFileError(f"{e}")
self.logger = Logger(__name__)
def _query(self, query: QueryImpl) -> list[dict]: