SRHarness / src /sr_harness /utils /log_exception.py
system's picture
system HF Staff
Deploy SRHarness v1.0.8 (f138545a336c)
8956871 verified
Raw History Blame Contribute Delete
652 Bytes
# Copyright (c) 2024-present, Yumeow. Licensed under the MIT License.
import traceback
from .tag2ansi import tag2ansi
def log_exception(e: Exception, with_traceback=True) -> str:
"""Format an exception (and optional traceback) as a concise diagnostic string for logging.
Args:
e: Exception instance to format.
with_traceback: Whether to include the formatted traceback lines.
Returns:
str: Formatted exception summary.
"""
return tag2ansi(
f"[red bold]{type(e).__name__}[reset]: "
f"[red]{str(e)}[reset]"
f"\n[gray]{traceback.format_exc() if with_traceback else ''}[reset]"
)