fix(canary): friendly "manifest not found" instead of a raw OS error

Live smoke: `soup data canary check --manifest nope.json` surfaced
"[WinError 2] Не удается найти указанный файл: 'nope.json'" -- a raw,
locale-dependent OS error leaking straight through from os.path.getsize,
where every other Soup command says "File not found: <path>".
This commit is contained in:
Alpamys 2026-07-16 22:53:19 +05:00
parent cf08cdf82f
commit fd51d5cfbe
2 changed files with 16 additions and 0 deletions

View File

@ -166,6 +166,10 @@ def _harden_permissions(path: str) -> None:
def load_manifest(path: str) -> tuple[Canary, ...]:
"""Read a canary manifest written by :func:`write_manifest`."""
safe = enforce_under_cwd_and_no_symlink(str(path), "manifest")
if not os.path.isfile(safe):
# Without this the caller surfaces a raw (locale-dependent) OS error
# from getsize — e.g. "[WinError 2] Не удается найти указанный файл".
raise ValueError(f"manifest not found: {path}")
if os.path.getsize(safe) > _MAX_MANIFEST_BYTES:
raise ValueError(
f"manifest too large (max {_MAX_MANIFEST_BYTES} bytes)"

View File

@ -1430,6 +1430,18 @@ class TestCanaryManifest:
generate_canaries(count=1, seed=0), str(tmp_path / "esc.json")
)
def test_missing_manifest_is_a_friendly_message(self, tmp_path, monkeypatch):
"""Not a raw locale-dependent OS error.
Live smoke surfaced "[WinError 2] Не удается найти указанный файл"
leaking straight through from os.path.getsize.
"""
from soup_cli.utils.canary import load_manifest
monkeypatch.chdir(tmp_path)
with pytest.raises(ValueError, match="manifest not found"):
load_manifest("nope.json")
def test_malformed_manifest_rejected(self, tmp_path, monkeypatch):
from pathlib import Path