Fix crash

This commit is contained in:
DazedAnon 2026-07-09 08:10:55 -05:00
parent 9be5d24fcd
commit 563d09db89
3 changed files with 19 additions and 3 deletions

View file

@ -1906,8 +1906,7 @@ class WolfWorkflowTab(QWidget):
layout.addWidget(checked_btn)
self._db_content_dist: wolf_db.ContentDistribution | None = None
self._refresh_db_discovery()
# Defer discovery until the step is shown - files/ may hold RPGMaker JSON.
def _wolf_json_work_dir(self) -> Path | None:
if not self._game_root:
return None

View file

@ -153,6 +153,21 @@ class TestContentDistribution(unittest.TestCase):
self.assertEqual(dist.map_files, 1)
self.assertEqual(dist.map_lines, 1)
def test_skips_rpgmaker_array_json(self):
"""files/ may hold RPGMaker list JSON; must not crash Wolf discovery."""
with tempfile.TemporaryDirectory() as tmp:
base = Path(tmp)
(base / "Actors.json").write_text(
json.dumps([{"id": 1, "name": "Hero"}]),
encoding="utf-8",
)
(base / "DataBase.project.json").write_text(
json.dumps(NARRATIVE_DB, ensure_ascii=False),
encoding="utf-8",
)
dist = wdb.analyze_content_distribution(base)
self.assertGreater(dist.db_lines, 0)
def test_discovery_summary_mentions_database(self):
with tempfile.TemporaryDirectory() as tmp:
base = Path(tmp)

View file

@ -183,10 +183,12 @@ def _count_json_lines(doc: dict[str, Any]) -> int:
def _load_json(path: Path) -> dict[str, Any] | None:
"""Load a WolfDawn JSON object. Skip arrays / non-objects (e.g. RPGMaker files/)."""
try:
return json.loads(path.read_text(encoding="utf-8-sig"))
data = json.loads(path.read_text(encoding="utf-8-sig"))
except Exception:
return None
return data if isinstance(data, dict) else None
@dataclass