mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-01 05:48:52 -06:00
fix: say why a local list beside --manifest fails
An oversized or unreadable standalone layout said "not valid: Expecting value", and an unreadable target list read as absent, so the offline run asked for the file already there. One reader of a capped local JSON file now says the cause: unreadable, too large or not JSON.
This commit is contained in:
1 parent
8d2f71b026
commit
ec50bf6b41
8 files changed
+112
-54
No files matched your search
@@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
@@ -239,6 +240,19 @@ def _replace_with_copy(src: Path, dest: Path) -> None:
|
||||
raise
|
||||
|
||||
|
||||
def read_local_json(path: Path, limit: int) -> object:
|
||||
"""A JSON file of limit bytes at most. OSError when it cannot be read,
|
||||
ValueError saying why when it is too large or not JSON."""
|
||||
with open(path, "rb") as handle:
|
||||
raw = handle.read(limit + 1)
|
||||
if len(raw) > limit:
|
||||
raise ValueError(f"it exceeds {limit} bytes")
|
||||
try:
|
||||
return json.loads(raw.decode("utf-8"))
|
||||
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
|
||||
raise ValueError(f"not JSON ({exc})") from exc
|
||||
|
||||
|
||||
def write_atomically(path: Path, data: bytes) -> None:
|
||||
"""Write data at path through a scratch file beside it, removed when the
|
||||
write fails; a scratch that cannot be removed is named in the error."""
|
||||
|
||||
Reference in new issue
Block a user