From 84783fdc4d99116f03e626ec88e334c25ac67b88 Mon Sep 17 00:00:00 2001 From: Mark Eaton Date: Wed, 17 Sep 2025 14:45:11 -0400 Subject: [PATCH] fix: handle empty pa11y stdout and forward stderr for JSON decode errors Co-authored-by: aider (o3) --- check_wcag_unique.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/check_wcag_unique.py b/check_wcag_unique.py index 507d310..5d62662 100644 --- a/check_wcag_unique.py +++ b/check_wcag_unique.py @@ -39,9 +39,19 @@ def run_pa11y(url: str) -> List[dict]: print(f"[ERROR] pa11y failed with code {result.returncode} for {url}", file=sys.stderr) return [] + # Handle cases where pa11y writes nothing (or only whitespace) to stdout. + if result.stdout is None or not result.stdout.strip(): + if result.stderr: + # Forward pa11y’s stderr so you can inspect what happened. + print(result.stderr, file=sys.stderr) + print(f"[WARN] pa11y produced no JSON output for {url}", file=sys.stderr) + return [] + try: return json.loads(result.stdout) except json.JSONDecodeError: + # Show the raw (invalid) output to aid troubleshooting. + print(result.stdout, file=sys.stderr) print(f"[WARN] Could not parse pa11y JSON output for {url}", file=sys.stderr) return []