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:
@@ -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 []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user