Skip to content
Snippets Groups Projects
Unverified Commit 28e3f98d authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

show proper error if input filename doesn't exist

parent 518e1719
Branches
Tags
No related merge requests found
......@@ -7,3 +7,4 @@ class GPLTError(Enum):
MODULE_SHOULD_NOT_RUN = 2
COULD_NOT_DECODE_JSON = 3
COULD_NOT_CONVERT = 4
NO_SUCH_FILE = 5
......@@ -14,6 +14,8 @@ def panic(err: GPLTError, msg: str):
x = "COULD_NOT_DECODE_JSON"
case GPLTError.COULD_NOT_CONVERT:
x = "COULD_NOT_CONVERT"
case GPLTError.NO_SUCH_FILE:
x = "NO_SUCH_FILE"
case _:
print(f"[bold red]PANIC[/bold red]: unexpected error: {err} is not known")
exit(1)
......
......@@ -16,6 +16,11 @@ VERSION = "{{VERSION}}"
def load_json(json_value: str, filename: str = None):
if filename is not None:
if not os.path.exists(filename):
panic(
GPLTError.NO_SUCH_FILE,
f"{filename}: no such file",
)
info(f"loading JSON data from {filename}")
with open(filename, "r") as file:
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment