Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/known_good_correct.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
uses: actions/checkout@v4.2.2
- name: Check
run: |
ls -la
scripts/known_good/update_module_from_known_good.py --known known_good.json --output-dir-modules bazel_common
if git diff --quiet; then
echo "No changes"
Expand Down
20 changes: 18 additions & 2 deletions scripts/known_good/models/known_good.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,24 @@ def load_known_good(path: Path) -> KnownGood:
"""

with open(path, "r", encoding="utf-8") as f:
data = json.load(f)

text = f.read()
try:
data = json.loads(text)
except json.JSONDecodeError as e:
lines = text.splitlines()
line = lines[e.lineno - 1] if 0 <= e.lineno - 1 < len(lines) else ""
pointer = " " * (e.colno - 1) + "^"

hint = ""
if "Expecting value" in e.msg:
hint = "Possible causes: trailing comma, missing value, or extra comma."

raise ValueError(
f"Invalid JSON at line {e.lineno}, column {e.colno}\n"
f"{line}\n{pointer}\n"
f"{e.msg}. {hint}"
) from None

if not isinstance(data, dict) or not isinstance(data.get("modules"), dict):
raise ValueError(
f"Invalid known_good.json at {path} (expected object with 'modules' dict)"
Expand Down