ai_se/DebugLogger.py

38 lines
1.2 KiB
Python

import streamlit as st
import subprocess
error_log = []
def log_error(error_message):
st.session_state["bugs"] = error_message
#if "bugs" not in st.session_state:
# st.session_state["bugs"] = ""
#if "bugs" in st.session_state:
#error_log.append(error_message)
def format_debug_output(output: dict) -> str:
"""Format debug output dictionary into a readable 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)
#qwen
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"