ai_se/DebugLogger.py

32 lines
1.1 KiB
Python

import streamlit as st
import subprocess
def log_error(error_message):
#speichern des strukturierten outputs von qwen über session_state
st.session_state["bugs"] = error_message
def format_debug_output(output: dict) -> str:
#formatiert das dictionary in einen lesbareren string
lines = ["=== DEBUG REPORT ===",
f"Summary: {output.get('summary', 'N/A')}",
f"Quality: {output.get('overall_quality', 'N/A')}",
"\n=== ISSUES ==="]
for bug in output.get('bugs', []):
lines.append(f"[{bug.get('severity')}] Line {bug.get('line')}")
lines.append(f" Description: {bug.get('description')}")
lines.append(f" Fix: {bug.get('fix')}\n")
return "\n".join(lines)
def format_output(text: bytes) -> str:
return text.decode('utf-8', errors='replace').strip()
def format_error(exc: Exception) -> str:
msg = ""
if hasattr(exc, 'stderr') and exc.stderr:
msg = exc.stderr.decode('utf-8', errors='replace').strip()
if isinstance(exc, subprocess.CalledProcessError):
msg = f"[Exit: {exc.returncode}] {msg}"
return msg or "Execution failed"