{"record":{"id":"5f9c79246dafc35b","repo":"sansan0/TrendRadar","slug":"week-map-weekday","errorCode":null,"errorMessage":"week_map 缺少星期映射: {weekday}","messagePattern":"week_map 缺少星期映射: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"trendradar/core/scheduler.py","lineNumber":131,"sourceCode":"                period_name=None,\n                day_plan=\"disabled\",\n                collect=True,\n                analyze=True,\n                push=True,\n                report_mode=self.fallback_report_mode,\n                ai_mode=\"follow_report\",\n                once_analyze=False,\n                once_push=False,\n            )\n\n        now = self.get_time()\n        weekday = now.isoweekday()  # 1=周一 ... 7=周日\n        now_hhmm = now.strftime(\"%H:%M\")\n\n        # 查找当天的日计划\n        day_plan_key = self.timeline[\"week_map\"].get(weekday)\n        if day_plan_key is None:\n            raise ValueError(f\"week_map 缺少星期映射: {weekday}\")\n\n        day_plan = self.timeline[\"day_plans\"].get(day_plan_key)\n        if day_plan is None:\n            raise ValueError(f\"week_map[{weekday}] 引用了不存在的 day_plan: {day_plan_key}\")\n\n        # 查找当前活跃的时间段\n        period_key = self._find_active_period(now_hhmm, day_plan)\n\n        # 合并默认配置和时间段配置\n        merged = self._merge_with_default(period_key)\n\n        # 打印调度日志\n        weekday_names = {1: \"一\", 2: \"二\", 3: \"三\", 4: \"四\", 5: \"五\", 6: \"六\", 7: \"日\"}\n        period_display = \"默认配置（未命中任何时间段）\"\n        if period_key:\n            period_cfg = self.timeline[\"periods\"][period_key]\n            period_name = period_cfg.get(\"name\", period_key)\n            start = period_cfg.get(\"start\", \"?\")","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/trendradar/core/scheduler.py#L113-L149","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# timeline config\n# before\nweek_map: {1: workday, 2: workday, 3: workday, 4: workday, 5: workday}\n# after\nweek_map: {1: workday, 2: workday, 3: workday, 4: workday, 5: workday, 6: rest, 7: rest}","handlingStrategy":"validation","validationCode":"week_map = timeline.get(\"week_map\", {})\nmissing = [d for d in range(1, 8) if d not in week_map]\nif missing:\n    for d in missing:\n        week_map[d] = \"rest\"          # or raise with a clear message\n    timeline.setdefault(\"day_plans\", {})[\"rest\"] = {\"periods\": []}\n# then resolve()","typeGuard":"def week_map_complete(timeline: dict) -> bool:\n    return all(d in timeline.get(\"week_map\", {}) for d in range(1, 8))","tryCatchPattern":"try:\n    cfg = scheduler.resolve()\nexcept ValueError as e:\n    if \"week_map 缺少星期映射\" in str(e):\n        raise SystemExit(f\"schedule config error: {e}; map days 6/7 to a rest day_plan\")\n    raise","preventionTips":["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."],"tags":["scheduler","config","week-map","runtime"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}