Handle invalid UTF-8 with replacement decoding

This commit is contained in:
jxxghp
2026-06-21 09:56:34 +08:00
parent 99e369aaa4
commit 68f18db374
29 changed files with 139 additions and 121 deletions
+3 -3
View File
@@ -131,7 +131,7 @@ def _read_json(path: Path) -> Optional[dict[str, Any]]:
if not path.exists():
return None
try:
data = json.loads(path.read_text(encoding="utf-8"))
data = json.loads(path.read_text(encoding="utf-8", errors="replace"))
except (OSError, json.JSONDecodeError):
return None
return data if isinstance(data, dict) else None
@@ -249,7 +249,7 @@ def _backend_health_payload(port: int, timeout: float = BACKEND_HEALTH_TIMEOUT)
with urlopen(request, timeout=timeout) as response:
if response.status != 200:
return None
raw = response.read().decode("utf-8", errors="ignore")
raw = response.read().decode("utf-8", errors="replace")
except (HTTPError, URLError):
return None
except OSError:
@@ -672,7 +672,7 @@ def _check_frontend_assets(runner: DoctorRunnerProtocol) -> None:
version = ""
try:
version = (frontend_dir / "version.txt").read_text(encoding="utf-8").strip()
version = (frontend_dir / "version.txt").read_text(encoding="utf-8", errors="replace").strip()
except OSError:
version = "unknown"
runner.add(