| | import os |
| | import sys |
| |
|
| | from serena.agent import log |
| |
|
| |
|
| | def is_headless_environment() -> bool: |
| | """ |
| | Detect if we're running in a headless environment where GUI operations would fail. |
| | |
| | Returns True if: |
| | - No DISPLAY variable on Linux/Unix |
| | - Running in SSH session |
| | - Running in WSL without X server |
| | - Running in Docker container |
| | """ |
| | |
| | if sys.platform == "win32": |
| | return False |
| |
|
| | |
| | if not os.environ.get("DISPLAY"): |
| | return True |
| |
|
| | |
| | if os.environ.get("SSH_CONNECTION") or os.environ.get("SSH_CLIENT"): |
| | return True |
| |
|
| | |
| | if os.environ.get("CI") or os.environ.get("CONTAINER") or os.path.exists("/.dockerenv"): |
| | return True |
| |
|
| | |
| | if hasattr(os, "uname"): |
| | if "microsoft" in os.uname().release.lower(): |
| | |
| | |
| | return True |
| |
|
| | return False |
| |
|
| |
|
| | 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. |
| | """ |
| | |
| | log.error(f"Fatal exception: {e}", exc_info=e) |
| | print(f"Fatal exception: {e}", file=sys.stderr) |
| |
|
| | |
| | if is_headless_environment(): |
| | log.debug("Skipping GUI error display in headless environment") |
| | return |
| |
|
| | |
| | try: |
| | |
| | |
| | from serena.gui_log_viewer import show_fatal_exception |
| |
|
| | show_fatal_exception(e) |
| | except Exception as gui_error: |
| | log.debug(f"Failed to show GUI error dialog: {gui_error}") |
| |
|