Answer the architect: fail a judge that answers without interrupting, read every checkout file through one function
This commit is contained in:
@@ -27,3 +27,13 @@ def worktrees(root: str, effects: Effects) -> list[str]:
|
||||
|
||||
def project_key(root: str, code: pathlib.Path) -> str:
|
||||
return root.removeprefix(f"{code}/").lstrip("/")
|
||||
|
||||
|
||||
def read_checkout_file(root: str, name: str, consequence: str) -> str | Stop:
|
||||
try:
|
||||
return pathlib.Path(root, name).read_text(encoding="utf-8")
|
||||
except OSError as failure:
|
||||
return Stop(1, f"{name} in {root}: {failure.strerror} - {consequence}.")
|
||||
except UnicodeDecodeError as failure:
|
||||
line = failure.object.count(b"\n", 0, failure.start) + 1
|
||||
return Stop(1, f"{name} is not UTF-8 on line {line} - {consequence}.")
|
||||
|
||||
Reference in New Issue
Block a user