fix: ignore invalid CAI JSON dumps

This commit is contained in:
11b 2022-12-23 16:45:09 -03:00
parent d91367e902
commit cef8f54fc4
1 changed files with 7 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import json
import logging
import os
import typing as t
from dataclasses import dataclass
@ -6,6 +7,8 @@ from dataclasses import dataclass
from waifu.datasets import BaseDataset
from waifu.utils.dataset import get_data_path
logger = logging.getLogger(__name__)
@dataclass(frozen=True)
class CaiBotInfo:
@ -96,7 +99,10 @@ def _available_json_data() -> t.Generator[dict[str, t.Any], None, None]:
folder_path = os.path.join(dataset_path, folder)
for json_file_path in _enumerate_json_files(folder_path):
with open(json_file_path, "r", encoding="utf-8") as json_file:
yield json.load(json_file)
try:
yield json.load(json_file)
except json.decoder.JSONDecodeError as ex:
logger.error("Failed to parse %s: %s", json_file_path, ex)
def _bot_info_from_dict(info_dict: dict[str, t.Any]) -> CaiBotInfo: