From 11ade7738a74afead767f5b07823813d7ef0f064 Mon Sep 17 00:00:00 2001 From: Pawel Rutka Date: Wed, 25 Feb 2026 15:41:42 +0100 Subject: [PATCH] Make parsing know_good.json be more verbose on errors --- .github/workflows/known_good_correct.yml | 1 - scripts/known_good/models/known_good.py | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/known_good_correct.yml b/.github/workflows/known_good_correct.yml index 95ce610298..03b6536003 100644 --- a/.github/workflows/known_good_correct.yml +++ b/.github/workflows/known_good_correct.yml @@ -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" diff --git a/scripts/known_good/models/known_good.py b/scripts/known_good/models/known_good.py index 788af68831..a0ea976655 100644 --- a/scripts/known_good/models/known_good.py +++ b/scripts/known_good/models/known_good.py @@ -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)"