Skip to content

Commit 004a565

Browse files
pawelrutkaqrmaddikery
authored andcommitted
Make parsing know_good.json be more verbose on errors (eclipse-score#160)
1 parent 55d8776 commit 004a565

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.github/workflows/known_good_correct.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
uses: actions/[email protected]
3232
- name: Check
3333
run: |
34-
ls -la
3534
scripts/known_good/update_module_from_known_good.py --known known_good.json --output-dir-modules bazel_common
3635
if git diff --quiet; then
3736
echo "No changes"

scripts/known_good/models/known_good.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,24 @@ def load_known_good(path: Path) -> KnownGood:
9595
"""
9696

9797
with open(path, "r", encoding="utf-8") as f:
98-
data = json.load(f)
99-
98+
text = f.read()
99+
try:
100+
data = json.loads(text)
101+
except json.JSONDecodeError as e:
102+
lines = text.splitlines()
103+
line = lines[e.lineno - 1] if 0 <= e.lineno - 1 < len(lines) else ""
104+
pointer = " " * (e.colno - 1) + "^"
105+
106+
hint = ""
107+
if "Expecting value" in e.msg:
108+
hint = "Possible causes: trailing comma, missing value, or extra comma."
109+
110+
raise ValueError(
111+
f"Invalid JSON at line {e.lineno}, column {e.colno}\n"
112+
f"{line}\n{pointer}\n"
113+
f"{e.msg}. {hint}"
114+
) from None
115+
100116
if not isinstance(data, dict) or not isinstance(data.get("modules"), dict):
101117
raise ValueError(
102118
f"Invalid known_good.json at {path} (expected object with 'modules' dict)"

0 commit comments

Comments
 (0)