fix: rebuild the database named in the error

This commit is contained in:
Abdessamad Derraz committed 2026-10-19 04:19:12 +02:00
1 parent 642896346f
commit 6008fe352c
2 files changed
+20 -2

No files matched your search

+2 -2
View File
@@ -59,12 +59,12 @@ def load_database(db_path: str) -> dict:
except FileNotFoundError:
raise DatabaseUnreadable(
f"{db_path} not found. Build it with: python scripts/generate_db.py "
"--force --bios-dir bios --output database.json"
f"--force --bios-dir bios --output {db_path}"
) from None
except json.JSONDecodeError as exc:
raise DatabaseUnreadable(
f"{db_path} is not valid JSON ({exc}). Rebuild it with: "
"python scripts/generate_db.py --force --bios-dir bios --output database.json"
f"python scripts/generate_db.py --force --bios-dir bios --output {db_path}"
) from None
+18
View File
@@ -5132,5 +5132,23 @@ class StrictFailsOnMissingOnly(unittest.TestCase):
self.assertNotIn("or rejected", verify_mod._exit_if_strict.__doc__)
class TheRepairCommandWritesTheFileNamed(unittest.TestCase):
"""--db nosuch.json said to rebuild with --output database.json: the
command wrote another file and the next run failed the same way."""
def test_the_command_names_the_path(self):
from scripts.common import DatabaseUnreadable, load_database
with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory:
target = str(Path(directory) / "nosuch.json")
with self.assertRaises(DatabaseUnreadable) as caught:
load_database(target)
self.assertIn(f"--output {target}", str(caught.exception))
Path(target).write_text("{")
with self.assertRaises(DatabaseUnreadable) as caught:
load_database(target)
self.assertIn(f"--output {target}", str(caught.exception))
if __name__ == "__main__":
unittest.main()