sansan0/TrendRadar · error · ValueError
week_map[{weekday}] 引用了不存在的 day_plan: {day_plan_key}
Error message
week_map[{weekday}] 引用了不存在的 day_plan: {day_plan_key} What it means
Raised during resolve() when week_map maps the current weekday to a day_plan key that does not exist in timeline.day_plans. The reference is dangling: the plan was renamed or deleted but week_map still points at the old name. A matching startup check (_validate_timeline) exists, so reaching this at runtime implies validation was bypassed.
Source
Thrown at trendradar/core/scheduler.py:135
push=True,
report_mode=self.fallback_report_mode,
ai_mode="follow_report",
once_analyze=False,
once_push=False,
)
now = self.get_time()
weekday = now.isoweekday() # 1=周一 ... 7=周日
now_hhmm = now.strftime("%H:%M")
# 查找当天的日计划
day_plan_key = self.timeline["week_map"].get(weekday)
if day_plan_key is None:
raise ValueError(f"week_map 缺少星期映射: {weekday}")
day_plan = self.timeline["day_plans"].get(day_plan_key)
if day_plan is None:
raise ValueError(f"week_map[{weekday}] 引用了不存在的 day_plan: {day_plan_key}")
# 查找当前活跃的时间段
period_key = self._find_active_period(now_hhmm, day_plan)
# 合并默认配置和时间段配置
merged = self._merge_with_default(period_key)
# 打印调度日志
weekday_names = {1: "一", 2: "二", 3: "三", 4: "四", 5: "五", 6: "六", 7: "日"}
period_display = "默认配置(未命中任何时间段)"
if period_key:
period_cfg = self.timeline["periods"][period_key]
period_name = period_cfg.get("name", period_key)
start = period_cfg.get("start", "?")
end = period_cfg.get("end", "?")
period_display = f"{period_name} ({start}-{end})"
print(f"[调度] 星期{weekday_names.get(weekday, '?')},日计划: {day_plan_key}")View on GitHub (pinned to 8ee26026ba)
Solutions
- Add the missing day_plan with the exact key week_map references, or update week_map to the new plan name.
- Search the timeline config for all references to the renamed plan and update each.
- Validate the timeline at startup (call _validate_timeline / rely on the normal startup path) so this surfaces immediately, not mid-run.
Example fix
# before
week_map: {1: workday} # day_plans defines 'weekday'
day_plans: {weekday: {...}}
# after
week_map: {1: weekday}
day_plans: {weekday: {...}} Defensive patterns
Strategy: validation
Validate before calling
for day, plan_key in timeline["week_map"].items():
if plan_key not in timeline["day_plans"]:
raise ValueError(
f"week_map[{day}] -> missing day_plan '{plan_key}'"
)
# run before scheduler.resolve() Type guard
def day_plan_refs_valid(timeline: dict) -> bool:
plans = timeline.get("day_plans", {})
return all(k in plans for k in timeline.get("week_map", {}).values()) Try / catch
try:
cfg = scheduler.resolve()
except ValueError as e:
if "引用了不存在的 day_plan" in str(e):
# config bug: fix names and rebuild scheduler, do not retry blindly
raise SystemExit(f"schedule config error: {e}")
raise Prevention
- Rename day_plans and week_map entries in the same edit.
- Add a config lint step (or unit test) that checks week_map→day_plans references.
When it happens
Trigger: Renaming a day_plan (e.g. 'workday' → 'weekday') without updating week_map entries; deleting an unused-looking day_plan that is still referenced; loading externally constructed timelines without validation.
Common situations: Hand-editing the schedule config in two places and missing one; YAML indentation moving a plan under a different parent so day_plans keys change.
Related errors
- week_map 缺少星期映射: {weekday}
- week_map[{day}] 引用了不存在的 day_plan: {plan_key}
- day_plan '{plan_key}' 中时间段 '{ranges[i][0]}' ({ranges[i][1]}-
- 不支持的传输模式: {transport}
- DATA_NOT_FOUND
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/ca739e7001fb0c41.
Report an issue: GitHub.