sansan0/TrendRadar · error · ValueError
week_map[{day}] 引用了不存在的 day_plan: {plan_key}
Error message
week_map[{day}] 引用了不存在的 day_plan: {plan_key} What it means
Raised by _validate_timeline's referential-integrity pass when a week_map entry points at a day_plan key that is not defined. It iterates every (day, plan_key) pair and fails on the first dangling reference. This is the startup-time twin of the runtime error at scheduler.py:135.
Source
Thrown at trendradar/core/scheduler.py:333
启动时校验 timeline 配置
Raises:
ValueError: 配置不合法时抛出
"""
required_top_keys = ["default", "periods", "day_plans", "week_map"]
for key in required_top_keys:
if key not in timeline:
raise ValueError(f"timeline 缺少必须字段: {key}")
# week_map 必须覆盖 1..7
for day in range(1, 8):
if day not in timeline["week_map"]:
raise ValueError(f"week_map 缺少星期映射: {day}")
# day_plan 引用完整性
for day, plan_key in timeline["week_map"].items():
if plan_key not in timeline["day_plans"]:
raise ValueError(
f"week_map[{day}] 引用了不存在的 day_plan: {plan_key}"
)
# period 引用完整性
for plan_key, plan in timeline["day_plans"].items():
for period_key in plan.get("periods", []):
if period_key not in timeline["periods"]:
raise ValueError(
f"day_plan[{plan_key}] 引用了不存在的 period: {period_key}"
)
# 时间格式校验
for period_key, period in timeline["periods"].items():
if "start" not in period or "end" not in period:
raise ValueError(
f"period '{period_key}' 缺少 start 或 end 字段"
)
self._validate_hhmm(period["start"], f"{period_key}.start")View on GitHub (pinned to 8ee26026ba)
Solutions
- Align names: either restore/define the day_plan key week_map references, or update week_map to an existing key.
- Check for invisible whitespace and casing differences between the two sections.
- Keep renames atomic — update week_map in the same edit as day_plans.
Example fix
# before
week_map: {1: workday}
day_plans: {workdays: {periods: []}}
# after
week_map: {1: workdays}
day_plans: {workdays: {periods: []}} Defensive patterns
Strategy: validation
Validate before calling
plans = timeline.get("day_plans", {})
for day, key in timeline.get("week_map", {}).items():
if key not in plans:
raise ValueError(f"week_map[{day}] references undefined day_plan '{key}'") Type guard
def no_dangling_day_plan_refs(t: dict) -> bool:
plans = set(t.get("day_plans", {}))
return set(t.get("week_map", {}).values()) <= plans Try / catch
try:
scheduler = Scheduler(schedule_config, timeline_data)
except ValueError as e:
if "引用了不存在的 day_plan" in str(e):
raise SystemExit(f"schedule config error: {e}; align week_map and day_plans names")
raise Prevention
- Update week_map references in the same commit as day_plan renames.
- Validate referential integrity in a config-lint test.
When it happens
Trigger: week_map: {1: workday} while day_plans defines only 'weekday'; renaming or deleting a day_plan without updating week_map; a plan key with a trailing space or different casing.
Common situations: Rename refactors applied to day_plans but not week_map; YAML duplicate-key issues silently dropping a plan; case mismatches ('Work' vs 'work').
Related errors
- 不支持的传输模式: {transport}
- DATA_NOT_FOUND
- 未知的预设模板: '{preset}',可选值: {', '.join(presets.keys())}, custom
- week_map[{weekday}] 引用了不存在的 day_plan: {day_plan_key}
- timeline 缺少必须字段: {key}
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/0d3d19ee09e3af95.
Report an issue: GitHub.