tools: handle UnicodeError in arch_gate, resolve relative LLAMA overrides, and validate finite --seconds/write errors

This commit is contained in:
morebrackets
2026-12-02 03:59:02 -08:00
parent a9397c2104
commit 64f1e9a2c5
3 changed files with 11 additions and 7 deletions

View File

@ -74,8 +74,8 @@ def main():
help="fail if the implementation is N (0xb = GB20y/Tegra)")
arguments = parser.parse_args()
try:
report = json.loads(arguments.report.read_text())
except (OSError, json.JSONDecodeError) as exc:
report = json.loads(arguments.report.read_text(encoding="utf-8"))
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
print(json.dumps({"passed": False, "reason": f"failed to read report: {exc}"}, indent=2))
raise SystemExit(1)
if not isinstance(report, dict):

View File

@ -20,7 +20,7 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
def _pick_path(env_var: str, rel_path: str) -> Path:
override = os.environ.get(env_var)
if override:
return Path(override)
return Path(override).resolve()
local = REPO_ROOT / rel_path
if local.exists():
return local

View File

@ -11,6 +11,7 @@ is a set of observed states and not a trace. Run with sudo.
"""
import argparse
import json
import math
import mmap
import os
from pathlib import Path
@ -32,8 +33,8 @@ def parse_args(argv=None):
arguments = parser.parse_args(argv)
if not re.fullmatch(r"[0-9a-f]{4}:[0-9a-f]{2}:[0-9a-f]{2}\.[0-7]", arguments.pci):
parser.error("a lowercase domain:bus:device.function is required")
if arguments.seconds <= 0:
parser.error("--seconds must be positive")
if not math.isfinite(arguments.seconds) or arguments.seconds <= 0:
parser.error("--seconds must be a finite positive number")
if arguments.distinct < 1:
parser.error("--distinct must be >= 1")
return arguments
@ -76,8 +77,11 @@ def main(argv=None) -> int:
for offset, values in sorted(seen.items())}}
text = json.dumps(report, indent=1) + "\n"
if arguments.out:
arguments.out.parent.mkdir(parents=True, exist_ok=True)
arguments.out.write_text(text)
try:
arguments.out.parent.mkdir(parents=True, exist_ok=True)
arguments.out.write_text(text, encoding="utf-8")
except OSError as exc:
raise SystemExit(f"cannot write {arguments.out}: {exc.strerror or exc}")
print(text, end="")
return 0