import json
import subprocess
r = subprocess.run(['uv', 'run', 'python', 'scripts/audit_exception_handling.py', '--json'], capture_output=True, text=True)
data = json.loads(r.stdout)
app = [f for f in data['files'] if 'app_controller' in f.get('filename', '')][0]
findings = app['findings']
silent = [f for f in findings if f.get('category') == 'INTERNAL_SILENT_SWALLOW']
print(f'INTERNAL_SILENT_SWALLOW: {len(silent)} sites')
for f in silent:
    line = f.get('line', 0)
    ctx = f.get('context', '')
    print(f'  L{line}: {ctx[:60]}')
print()
rethrow = [f for f in findings if f.get('category') == 'INTERNAL_RETHROW']
print(f'INTERNAL_RETHROW: {len(rethrow)} sites')
for f in rethrow:
    line = f.get('line', 0)
    ctx = f.get('context', '')
    print(f'  L{line}: {ctx[:60]}')
print()
optional = [f for f in findings if f.get('category') == 'INTERNAL_OPTIONAL_RETURN']
print(f'INTERNAL_OPTIONAL_RETURN: {len(optional)} sites')
for f in optional:
    line = f.get('line', 0)
    ctx = f.get('context', '')
    print(f'  L{line}: {ctx[:60]}')
