mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-07 01:48:53 +00:00
fix(cron): validate expression syntax in _validate_schedule_for_add
This commit is contained in:
parent
c6bd5f0075
commit
73a0080484
@ -75,13 +75,20 @@ def _validate_schedule_for_add(schedule: CronSchedule) -> None:
|
|||||||
if schedule.tz and schedule.kind != "cron":
|
if schedule.tz and schedule.kind != "cron":
|
||||||
raise ValueError("tz can only be used with cron schedules")
|
raise ValueError("tz can only be used with cron schedules")
|
||||||
|
|
||||||
if schedule.kind == "cron" and schedule.tz:
|
if schedule.kind == "cron":
|
||||||
|
if not schedule.expr or not schedule.expr.strip():
|
||||||
|
raise ValueError("cron schedule requires a non-empty 'expr'")
|
||||||
try:
|
try:
|
||||||
from zoneinfo import ZoneInfo
|
from croniter import croniter
|
||||||
|
croniter(schedule.expr)
|
||||||
ZoneInfo(schedule.tz)
|
except Exception as e:
|
||||||
except Exception:
|
raise ValueError(f"invalid cron expression '{schedule.expr}': {e}") from None
|
||||||
raise ValueError(f"unknown timezone '{schedule.tz}'") from None
|
if schedule.tz:
|
||||||
|
try:
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
ZoneInfo(schedule.tz)
|
||||||
|
except Exception:
|
||||||
|
raise ValueError(f"unknown timezone '{schedule.tz}'") from None
|
||||||
|
|
||||||
|
|
||||||
def _has_legacy_delivery_context(payload: CronPayload) -> bool:
|
def _has_legacy_delivery_context(payload: CronPayload) -> bool:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user