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:
Abdessamad Derraz committed 2026-11-21 06:04:39 +01:00
1 parent 8d2f71b026
commit ec50bf6b41
8 files changed
+112 -54

No files matched your search

+15 -19
View File
@@ -16,7 +16,7 @@ from pathlib import Path
from typing import Any, NoReturn
from installer.events import EVENTS
from installer.host_fs import _is_file
from installer.host_fs import _is_file, read_local_json
from installer.manifest import _check_standalone_layouts, _validate_manifest, _validate_targets
from installer.offline import LOCAL, _Offline, _network_allowed, offline_named, offline_undo, offline_words
from installer.platforms import TARGET_PLATFORMS, display_name
@@ -86,19 +86,10 @@ NETWORK_ADVICE = (" Check the connection, and HTTPS_PROXY if this network needs
def read_local_manifest(path: Path, plat: str) -> dict:
"""A file list saved on disk, checked as a downloaded one is."""
try:
with open(path, "rb") as handle:
raw = handle.read(MAX_MANIFEST_BYTES + 1)
return _validate_manifest(read_local_json(path, MAX_MANIFEST_BYTES), plat)
except OSError as exc:
print(f" Cannot read the file list {path}: {exc.strerror or exc}.", file=sys.stderr)
sys.exit(1)
try:
if len(raw) > MAX_MANIFEST_BYTES:
raise ValueError(f"it exceeds {MAX_MANIFEST_BYTES} bytes")
try:
data = json.loads(raw.decode("utf-8"))
except (UnicodeDecodeError, json.JSONDecodeError) as exc:
raise ValueError(f"not JSON ({exc})") from exc
return _validate_manifest(data, plat)
except ValueError as exc:
EVENTS.emit("error", stage="manifest", reason="invalid", platform=plat,
message=f"the file list is not valid: {exc}")
@@ -449,12 +440,16 @@ def local_targets(plat: str) -> "dict | None":
if LOCAL.manifest is None:
return None
beside = LOCAL.manifest.parent / "targets" / f"{plat}.json"
raw = _read_capped(beside, MAX_TARGETS_BYTES)
if raw is None:
if not _is_file(beside):
return None
try:
return _validate_targets(json.loads(raw.decode("utf-8")))
except (UnicodeDecodeError, ValueError) as exc:
return _validate_targets(read_local_json(beside, MAX_TARGETS_BYTES))
except OSError as exc:
# Read as absent, the offline run asked for the file already there.
print(f" Error: the target list {beside} cannot be read: {exc.strerror or exc}",
file=sys.stderr)
sys.exit(1)
except ValueError as exc:
print(f" Error: the target list {beside} is not valid: {exc}", file=sys.stderr)
sys.exit(1)
@@ -470,16 +465,17 @@ def fetch_standalone(plat: str, manifest: dict) -> dict:
where = str(beside) if beside is not None and _is_file(beside) else url
try:
if where != url:
raw = _read_capped(Path(where), MAX_STANDALONE_BYTES)
data = json.loads((raw or b"").decode("utf-8"))
data = read_local_json(Path(where), MAX_STANDALONE_BYTES)
else:
data = _fetch_json(url, MAX_STANDALONE_BYTES, "standalone layout")
return _check_standalone_layouts(data, manifest, plat)
except urllib.error.HTTPError as exc:
problem = f"HTTP {exc.code}"
except (urllib.error.URLError, OSError) as exc:
problem = str(exc) if isinstance(exc, _Offline) else network_words(exc)[1]
except (UnicodeDecodeError, ValueError) as exc:
problem = (str(exc) if isinstance(exc, _Offline)
else exc.strerror or str(exc) if where != url
else network_words(exc)[1])
except ValueError as exc:
problem = f"not valid: {exc}"
EVENTS.emit("error", stage="manifest", reason="unavailable", platform=plat,
message=f"--standalone needs {where}: {problem}")