Improve error messages from translation script (#102098)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Erik Montnemery
2023-10-22 23:45:27 +02:00
committed by GitHub
parent bc45de627a
commit 164872e1af
8 changed files with 59 additions and 24 deletions

View File

@@ -1,10 +1,12 @@
"""Translation utils."""
import argparse
import json
import os
import pathlib
import subprocess
from typing import Any
from .error import ExitApp
from .error import ExitApp, JSONDecodeErrorWithPath
def get_base_arg_parser() -> argparse.ArgumentParser:
@@ -55,3 +57,11 @@ def get_current_branch():
.stdout.decode()
.strip()
)
def load_json_from_path(path: pathlib.Path) -> Any:
"""Load JSON from path."""
try:
return json.loads(path.read_text())
except json.JSONDecodeError as err:
raise JSONDecodeErrorWithPath(err.msg, err.doc, err.pos, path) from err