14 lines
481 B
Python
14 lines
481 B
Python
import pathlib
|
|
|
|
from loop_claude.stop import Stop
|
|
|
|
|
|
def read_utf8(folder: str, name: str, consequence: str) -> str | Stop:
|
|
try:
|
|
return pathlib.Path(folder, name).read_text(encoding="utf-8")
|
|
except OSError as failure:
|
|
return Stop(1, f"{name} in {folder}: {failure.strerror} - {consequence}.")
|
|
except UnicodeDecodeError as failure:
|
|
line = failure.object.count(b"\n", 0, failure.start) + 1
|
|
return Stop(1, f"{name} in {folder} is not UTF-8 on line {line} - {consequence}.")
|