fix: handle empty pa11y stdout and forward stderr for JSON decode errors

Co-authored-by: aider (o3) <aider@aider.chat>
This commit is contained in:
Mark Eaton
2025-09-17 14:45:11 -04:00
co-authored by aider
parent 8c4303b31d
commit 84783fdc4d
+10
View File
@@ -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 pa11ys 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 []