refactor: enhance error handling with logging in various tools

- Added logging for exceptions in display.py, prompt_builder.py, browser_tool.py, code_execution_tool.py, terminal_tool.py to improve debugging and traceability.
- Updated exception handling to log specific error messages instead of silently passing, providing better insights into failures during execution.
- Ensured consistent use of logger.debug for non-critical errors across multiple files.
This commit is contained in:
teknium1 2026-03-11 05:27:54 -07:00
parent e4adb67ed8
commit 20b0e62f72
5 changed files with 50 additions and 47 deletions

View file

@ -1613,12 +1613,12 @@ def _cleanup_old_screenshots(screenshots_dir, max_age_hours=24):
cutoff = time.time() - (max_age_hours * 3600)
for f in screenshots_dir.glob("browser_screenshot_*.png"):
try:
if f.stat().st_mtime < cutoff:
f.unlink()
except Exception:
pass
except Exception:
pass # Non-critical — don't fail the screenshot operation
if f.stat().st_mtime < cutoff:
f.unlink()
except Exception as e:
logger.debug("Failed to clean old screenshot %s: %s", f, e)
except Exception as e:
logger.debug("Screenshot cleanup error (non-critical): %s", e)
def _cleanup_old_recordings(max_age_hours=72):
@ -1632,12 +1632,12 @@ def _cleanup_old_recordings(max_age_hours=72):
cutoff = time.time() - (max_age_hours * 3600)
for f in recordings_dir.glob("session_*.webm"):
try:
if f.stat().st_mtime < cutoff:
f.unlink()
except Exception:
pass
except Exception:
pass
if f.stat().st_mtime < cutoff:
f.unlink()
except Exception as e:
logger.debug("Failed to clean old recording %s: %s", f, e)
except Exception as e:
logger.debug("Recording cleanup error (non-critical): %s", e)
# ============================================================================
@ -1749,7 +1749,7 @@ def cleanup_browser(task_id: Optional[str] = None) -> None:
os.kill(daemon_pid, signal.SIGTERM)
logger.debug("Killed daemon pid %s for %s", daemon_pid, session_name)
except (ProcessLookupError, ValueError, PermissionError, OSError):
pass
logger.debug("Could not kill daemon pid for %s (already dead or inaccessible)", session_name)
shutil.rmtree(socket_dir, ignore_errors=True)
logger.debug("Removed task %s from active sessions", task_id)