fix: handle invalid ISO datetime in CronTool gracefully

datetime.fromisoformat(at) raises ValueError for malformed strings,
which propagated uncaught and crashed the tool execution. Now catches
ValueError and returns a user-friendly error message instead.
This commit is contained in:
Kiplangatkorir
2026-03-04 10:55:17 +03:00
parent 1303cc6669
commit edaf7a244a

View File

@@ -122,7 +122,10 @@ class CronTool(Tool):
elif at: elif at:
from datetime import datetime from datetime import datetime
dt = datetime.fromisoformat(at) try:
dt = datetime.fromisoformat(at)
except ValueError:
return f"Error: invalid ISO datetime format '{at}'. Expected format: YYYY-MM-DDTHH:MM:SS"
at_ms = int(dt.timestamp() * 1000) at_ms = int(dt.timestamp() * 1000)
schedule = CronSchedule(kind="at", at_ms=at_ms) schedule = CronSchedule(kind="at", at_ms=at_ms)
delete_after = True delete_after = True