mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 06:15:43 +00:00
Move show_fatal_exception_safe to new module util.exception
This commit is contained in:
1 parent
80a4caf36a
commit
ebfe72409f
5 files changed
+32
-48
No files matched your search
+1
-22
@@ -19,7 +19,7 @@ from typing import TYPE_CHECKING, Any, TypeVar, Union
|
||||
import click
|
||||
from pathspec import PathSpec
|
||||
from sensai.util import logging
|
||||
from sensai.util.logging import FallbackHandler, LogTime
|
||||
from sensai.util.logging import LogTime
|
||||
|
||||
from serena import serena_version
|
||||
from serena.config.context_mode import SerenaAgentContext, SerenaAgentMode
|
||||
@@ -46,27 +46,6 @@ SUCCESS_RESULT = "OK"
|
||||
DEFAULT_TOOL_TIMEOUT: float = 240
|
||||
|
||||
|
||||
def show_fatal_exception_safe(e: Exception) -> None:
|
||||
"""
|
||||
Shows the given exception in the GUI log viewer on the main thread and ensures that the exception is logged or at
|
||||
least printed to stderr.
|
||||
"""
|
||||
# Make sure the error is logged (adding a fallback handler which writes to stderr in case there is no other handler)
|
||||
fallback_handler = FallbackHandler(logging.StreamHandler(sys.stderr))
|
||||
Logger.root.addHandler(fallback_handler)
|
||||
log.error(f"Fatal exception: {e}", exc_info=e)
|
||||
|
||||
# attempt to show the error in the GUI
|
||||
try:
|
||||
# NOTE: The import can fail on macOS if Tk is not available (depends on Python interpreter installation, which uv
|
||||
# used as a base); while tkinter as such is always available, its dependencies can be unavailable on macOS.
|
||||
from serena.gui_log_viewer import show_fatal_exception
|
||||
|
||||
show_fatal_exception(e)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class ProjectNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
+2
-1
@@ -14,9 +14,10 @@ from agno.tools.toolkit import Toolkit
|
||||
from dotenv import load_dotenv
|
||||
from sensai.util.logging import LogTime
|
||||
|
||||
from serena.agent import SerenaAgent, Tool, show_fatal_exception_safe
|
||||
from serena.agent import SerenaAgent, Tool
|
||||
from serena.config.context_mode import SerenaAgentContext
|
||||
from serena.constants import REPO_ROOT
|
||||
from serena.util.exception import show_fatal_exception_safe
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -4,18 +4,15 @@ The Serena Model Context Protocol (MCP) Server
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass, field
|
||||
from functools import cached_property
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Self, TypeVar
|
||||
|
||||
import yaml
|
||||
from ruamel.yaml.comments import CommentedMap
|
||||
from sensai.util import logging
|
||||
from sensai.util.logging import FallbackHandler
|
||||
from sensai.util.string import ToStringMixin
|
||||
|
||||
from serena.constants import (
|
||||
@@ -38,27 +35,6 @@ T = TypeVar("T")
|
||||
DEFAULT_TOOL_TIMEOUT: float = 240
|
||||
|
||||
|
||||
def show_fatal_exception_safe(e: Exception) -> None:
|
||||
"""
|
||||
Shows the given exception in the GUI log viewer on the main thread and ensures that the exception is logged or at
|
||||
least printed to stderr.
|
||||
"""
|
||||
# Make sure the error is logged (adding a fallback handler which writes to stderr in case there is no other handler)
|
||||
fallback_handler = FallbackHandler(logging.StreamHandler(sys.stderr))
|
||||
Logger.root.addHandler(fallback_handler)
|
||||
log.error(f"Fatal exception: {e}", exc_info=e)
|
||||
|
||||
# attempt to show the error in the GUI
|
||||
try:
|
||||
# NOTE: The import can fail on macOS if Tk is not available (depends on Python interpreter installation, which uv
|
||||
# used as a base); while tkinter as such is always available, its dependencies can be unavailable on macOS.
|
||||
from serena.gui_log_viewer import show_fatal_exception
|
||||
|
||||
show_fatal_exception(e)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class SerenaConfigError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
+1
-1
@@ -22,11 +22,11 @@ from sensai.util import logging
|
||||
from serena.agent import (
|
||||
SerenaAgent,
|
||||
SerenaConfig,
|
||||
show_fatal_exception_safe,
|
||||
)
|
||||
from serena.config.context_mode import SerenaAgentContext, SerenaAgentMode
|
||||
from serena.constants import DEFAULT_CONTEXT, DEFAULT_MODES
|
||||
from serena.tools import ToolInterface
|
||||
from serena.util.exception import show_fatal_exception_safe
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
LOG_FORMAT = "%(levelname)-5s %(asctime)-15s %(name)s:%(funcName)s:%(lineno)d - %(message)s"
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
from logging import Logger
|
||||
|
||||
from sensai.util import logging
|
||||
from sensai.util.logging import FallbackHandler
|
||||
|
||||
from serena.agent import log
|
||||
|
||||
|
||||
def show_fatal_exception_safe(e: Exception) -> None:
|
||||
"""
|
||||
Shows the given exception in the GUI log viewer on the main thread and ensures that the exception is logged or at
|
||||
least printed to stderr.
|
||||
"""
|
||||
# Make sure the error is logged (adding a fallback handler which writes to stderr in case there is no other handler)
|
||||
fallback_handler = FallbackHandler(logging.StreamHandler(sys.stderr))
|
||||
Logger.root.addHandler(fallback_handler)
|
||||
log.error(f"Fatal exception: {e}", exc_info=e)
|
||||
|
||||
# attempt to show the error in the GUI
|
||||
try:
|
||||
# NOTE: The import can fail on macOS if Tk is not available (depends on Python interpreter installation, which uv
|
||||
# used as a base); while tkinter as such is always available, its dependencies can be unavailable on macOS.
|
||||
from serena.gui_log_viewer import show_fatal_exception
|
||||
|
||||
show_fatal_exception(e)
|
||||
except:
|
||||
pass
|
||||
Reference in new issue
Block a user