add extra safety try catch

This commit is contained in:
LeonOstrez
2025-07-03 17:50:22 +02:00
parent 950e58ac9f
commit 471b1b4e85
3 changed files with 27 additions and 18 deletions

View File

@@ -251,7 +251,7 @@ class TechLead(RelevantFilesMixin, BaseAgent):
self.next_state.flag_tasks_as_modified()
await self.ui.send_epics_and_tasks(
self.next_state.current_epic.get("sub_epics", []),
self.next_state.epics[-1].get("sub_epics", []),
self.next_state.tasks,
)

View File

@@ -362,9 +362,9 @@ class StateManager:
# Flag tasks as modified so SQLAlchemy knows to save the changes
state.flag_tasks_as_modified()
except ValueError:
# Current task not found in tasks list - this shouldn't happen but handle gracefully
log.warning("Current task not found in tasks list, skipping log trimming")
except Exception as e:
# Handle any error during log trimming gracefully
log.warning(f"Error during log trimming: {e}, skipping log trimming")
pass
self.current_session = session

View File

@@ -13,21 +13,30 @@ def trim_logs(logs: str) -> str:
:param logs: Log text to trim
:return: Trimmed log text with the marker phrase removed
"""
if not logs:
return ""
try:
if not logs:
return ""
# Define marker phrases
markers = ["Here are the backend logs", "Here are the frontend logs"]
# Ensure we have a string
if not isinstance(logs, str):
logs = str(logs)
# Find the first occurrence of any marker
index = float("inf")
for marker in markers:
pos = logs.find(marker)
if pos != -1 and pos < index:
index = pos
# Define marker phrases
markers = ["Here are the backend logs", "Here are the frontend logs"]
# If a marker was found, trim the string
if index != float("inf"):
return logs[:index]
# Find the first occurrence of any marker
index = float("inf")
for marker in markers:
pos = logs.find(marker)
if pos != -1 and pos < index:
index = pos
return logs
# If a marker was found, trim the string
if index != float("inf"):
return logs[:index]
return logs
except Exception:
# If anything goes wrong, return the original input as string or empty string
return str(logs) if logs is not None else ""