1
0
mirror of https://github.com/lutris/lutris synced 2024-06-29 05:34:25 +00:00

Make lutris panic, crash and burn on key errors on DB game object because this should not be inconsistent

This commit is contained in:
Mathieu Comandon 2024-04-07 15:18:05 -07:00
parent 94b261c20f
commit 3866cf21bd
2 changed files with 19 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import json
import sys
import time
from typing import List, Optional
@ -124,7 +125,11 @@ class LibrarySyncer:
def _db_game_to_api(self, db_game):
"""Serialize DB game entry to a payload compatible with the API"""
categories = [self.categories[cat_id] for cat_id in self.games_categories.get(db_game["id"], [])]
try:
categories = [self.categories[cat_id] for cat_id in self.games_categories.get(db_game["id"], [])]
except KeyError:
self.panic_at_the_key_error(db_game, "id")
return
return {
"name": db_game["name"],
"slug": db_game["slug"],
@ -137,12 +142,23 @@ class LibrarySyncer:
"categories": categories,
}
def panic_at_the_key_error(self, db_game, key):
logger.error((("!" * 120) + "\n") * 240)
logger.exception("No installed_at key in db_game. CORRUPTED OBJECT!!!!!")
logger.exception("OBJECT CONTENT %s", db_game)
logger.error((("!" * 120) + "\n") * 24)
sys.exit(-999)
def _db_games_to_api(self, db_games, since=None):
"""Serialize a collection of games to API format, optionally filtering by date"""
payload = []
for db_game in db_games:
lastplayed = db_game["lastplayed"] or 0
installed_at = db_game["installed_at"] or 0
try:
installed_at = db_game["installed_at"] or 0
except KeyError:
self.panic_at_the_key_error(db_game, "installed_at")
if since and lastplayed < since and installed_at < since:
continue
payload.append(self._db_game_to_api(db_game))

View File

@ -113,6 +113,7 @@ def delete_known_dirs(prefix_path):
continue
os.remove(regfile)
def remove_empty_dirs(dirname):
empty_folders = []
for root, dirs, files in os.walk(dirname, topdown=True):