From 563d09db89e37483e12a67707aa4d6402c1cf5ae Mon Sep 17 00:00:00 2001 From: DazedAnon Date: Thu, 9 Jul 2026 08:10:55 -0500 Subject: [PATCH] Fix crash --- gui/wolf_workflow_tab.py | 3 +-- tests/test_wolf_db_classify.py | 15 +++++++++++++++ util/wolfdawn/db_classify.py | 4 +++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gui/wolf_workflow_tab.py b/gui/wolf_workflow_tab.py index ce1d364..d6cec27 100644 --- a/gui/wolf_workflow_tab.py +++ b/gui/wolf_workflow_tab.py @@ -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 diff --git a/tests/test_wolf_db_classify.py b/tests/test_wolf_db_classify.py index 50b5d46..07f2059 100644 --- a/tests/test_wolf_db_classify.py +++ b/tests/test_wolf_db_classify.py @@ -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) diff --git a/util/wolfdawn/db_classify.py b/util/wolfdawn/db_classify.py index 722f7f0..0b75e66 100644 --- a/util/wolfdawn/db_classify.py +++ b/util/wolfdawn/db_classify.py @@ -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