mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +00:00
feat: add useful error message for when the store manager cant be initialized
Refs: OPS-83
This commit is contained in:
parent
2c7394edfa
commit
45519743bd
1 changed files with 13 additions and 1 deletions
|
|
@ -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:
|
||||
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]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue