sansan0/TrendRadar · error · ValueError
week_map 缺少星期映射: {weekday}
Error message
week_map 缺少星期映射: {weekday} What it means
Raised at schedule resolution time when the current weekday (ISO 1=Mon..7=Sun) has no entry in timeline.week_map. This is the runtime lookup in resolve(), distinct from the startup validator (_validate_timeline) which pre-checks coverage of days 1..7 — hitting this means validation was skipped or the timeline was mutated after validation.
Source
Thrown at trendradar/core/scheduler.py:131
period_name=None,
day_plan="disabled",
collect=True,
analyze=True,
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", "?")View on GitHub (pinned to 8ee26026ba)
Solutions
- Add the missing weekday key to week_map, mapping it to a day_plan (an empty/rest plan is fine).
- Run _validate_timeline on any programmatically built timeline before resolve().
- To disable scheduling on a day, map it to a day_plan with an empty periods list rather than removing the key.
Example fix
# timeline config
# before
week_map: {1: workday, 2: workday, 3: workday, 4: workday, 5: workday}
# after
week_map: {1: workday, 2: workday, 3: workday, 4: workday, 5: workday, 6: rest, 7: rest} Defensive patterns
Strategy: validation
Validate before calling
week_map = timeline.get("week_map", {})
missing = [d for d in range(1, 8) if d not in week_map]
if missing:
for d in missing:
week_map[d] = "rest" # or raise with a clear message
timeline.setdefault("day_plans", {})["rest"] = {"periods": []}
# then resolve() Type guard
def week_map_complete(timeline: dict) -> bool:
return all(d in timeline.get("week_map", {}) for d in range(1, 8)) Try / catch
try:
cfg = scheduler.resolve()
except ValueError as e:
if "week_map 缺少星期映射" in str(e):
raise SystemExit(f"schedule config error: {e}; map days 6/7 to a rest day_plan")
raise Prevention
- Always run the scheduler's startup validation on loaded timelines.
- Express 'no schedule' as an empty day_plan, never as a missing week_map key.
When it happens
Trigger: A custom timeline whose week_map defines only some days (e.g. 1-5 for weekdays) and the process runs on Saturday/Sunday; hand-edited timeline disabling a day by deleting its key instead of mapping it to a rest plan.
Common situations: Users delete weekend entries intending 'no schedule on weekends', but the contract requires every day mapped (map to a day_plan with no periods instead). Loading a timeline from external data that bypasses _validate_timeline.
Related errors
- week_map[{weekday}] 引用了不存在的 day_plan: {day_plan_key}
- week_map 缺少星期映射: {day}
- 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/5f9c79246dafc35b.
Report an issue: GitHub.