{"record":{"id":"e55f15b730ebe1fc","repo":"ZhuLinsen/daily_stock_analysis","slug":"self-schedule-time-r","errorCode":null,"errorMessage":"无效的定时执行时间: {self.schedule_time!r}","messagePattern":"无效的定时执行时间: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/scheduler.py","lineNumber":138,"sourceCode":"        self._schedule_times_provider = schedule_times_provider\n        self.shutdown_handler = GracefulShutdown(register_signals=register_signals)\n        self._task_callback: Optional[Callable] = None\n        self._daily_job: Optional[Any] = None\n        self._daily_jobs: List[Any] = []\n        self._background_tasks: List[Dict[str, Any]] = []\n        self._running = False\n\n    def set_daily_task(self, task: Callable, run_immediately: bool = True):\n        \"\"\"\n        设置每日定时任务\n\n        Args:\n            task: 要执行的任务函数（无参数）\n            run_immediately: 是否在设置后立即执行一次\n        \"\"\"\n        self._task_callback = task\n        if not self._configure_daily_tasks(self.schedule_times):\n            raise ValueError(f\"无效的定时执行时间: {self.schedule_time!r}\")\n\n        if run_immediately:\n            logger.info(\"立即执行一次任务...\")\n            self._safe_run_task()\n\n    @staticmethod\n    def _is_valid_schedule_time(schedule_time: str) -> bool:\n        \"\"\"Validate time string in HH:MM 24-hour format.\"\"\"\n        candidate = (schedule_time or \"\").strip()\n        if not re.fullmatch(r\"(?:[01]\\d|2[0-3]):[0-5]\\d\", candidate):\n            return False\n        return True\n\n    def _cancel_daily_job(self) -> None:\n        \"\"\"Remove the currently registered daily job if one exists.\"\"\"\n        if self._daily_job is None and not self._daily_jobs:\n            return\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/scheduler.py#L120-L156","documentation":"ValueError from StockScheduler.set_daily_task when _configure_daily_tasks fails for the configured schedule times. Each time string must match strict HH:MM 24-hour format ((?:[01]\\d|2[0-3]):[0-5]\\d); if none of the configured times validate, configuration fails and this error names the offending schedule_time value.","triggerScenarios":"Constructing the scheduler with schedule_time like '9:00' (missing leading zero), '09:60', '24:00', '9am', or an empty string when schedule_times is None. The fallback list ends up containing no valid HH:MM value, _configure_daily_tasks returns falsy, and set_daily_task raises.","commonSituations":"CRON-style or 12-hour values pasted into SCHEDULE_TIME; missing zero-padding; whitespace-only env value; passing schedule_times as a list of malformed strings; daylight-saving or locale-specific time formats.","solutions":["Set the time to zero-padded 24-hour HH:MM, e.g. SCHEDULE_TIME=09:30","Fix every entry if schedule_times is a list — one bad entry can fail configuration","Trim whitespace and remove AM/PM suffixes or colon-seconds","Validate at startup with a regex like ^(?:[01]\\d|2[0-3]):[0-5]\\d$ before constructing the scheduler"],"exampleFix":"# before\nSCHEDULE_TIME=9:30am\n\n# after\nSCHEDULE_TIME=09:30","handlingStrategy":"validation","validationCode":"import re\n\ndef is_valid_schedule_time(value: str) -> bool:\n    return bool(re.fullmatch(r\"(?:[01]\\d|2[0-3]):[0-5]\\d\", (value or \"\").strip()))","typeGuard":null,"tryCatchPattern":"try:\n    scheduler.set_daily_task(task)\nexcept ValueError as exc:\n    log.error(\"Bad schedule time %s — use zero-padded HH:MM 24h\", exc)\n    raise","preventionTips":["Validate SCHEDULE_TIME with the HH:MM regex at config load","Document zero-padding explicitly in .env.example (09:30, not 9:30)","Test every entry when accepting lists of schedule times"],"tags":["config","scheduler","validation","time"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}