mirror of
https://github.com/lutris/lutris
synced 2024-07-01 06:34:26 +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:
parent
94b261c20f
commit
3866cf21bd
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
@ -124,7 +125,11 @@ class LibrarySyncer:
|
||||||
|
|
||||||
def _db_game_to_api(self, db_game):
|
def _db_game_to_api(self, db_game):
|
||||||
"""Serialize DB game entry to a payload compatible with the API"""
|
"""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 {
|
return {
|
||||||
"name": db_game["name"],
|
"name": db_game["name"],
|
||||||
"slug": db_game["slug"],
|
"slug": db_game["slug"],
|
||||||
|
@ -137,12 +142,23 @@ class LibrarySyncer:
|
||||||
"categories": categories,
|
"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):
|
def _db_games_to_api(self, db_games, since=None):
|
||||||
"""Serialize a collection of games to API format, optionally filtering by date"""
|
"""Serialize a collection of games to API format, optionally filtering by date"""
|
||||||
payload = []
|
payload = []
|
||||||
for db_game in db_games:
|
for db_game in db_games:
|
||||||
lastplayed = db_game["lastplayed"] or 0
|
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:
|
if since and lastplayed < since and installed_at < since:
|
||||||
continue
|
continue
|
||||||
payload.append(self._db_game_to_api(db_game))
|
payload.append(self._db_game_to_api(db_game))
|
||||||
|
|
|
@ -113,6 +113,7 @@ def delete_known_dirs(prefix_path):
|
||||||
continue
|
continue
|
||||||
os.remove(regfile)
|
os.remove(regfile)
|
||||||
|
|
||||||
|
|
||||||
def remove_empty_dirs(dirname):
|
def remove_empty_dirs(dirname):
|
||||||
empty_folders = []
|
empty_folders = []
|
||||||
for root, dirs, files in os.walk(dirname, topdown=True):
|
for root, dirs, files in os.walk(dirname, topdown=True):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user