sansan0/TrendRadar · error · ValueError
未知的预设模板: '{preset}',可选值: {', '.join(presets.keys())}, custom
Error message
未知的预设模板: '{preset}',可选值: {', '.join(presets.keys())}, custom What it means
Raised by the scheduler's timeline builder when schedule_config.preset is neither 'custom' nor a key of timeline_data.presets. The builder deep-copies either the custom timeline or a named preset; an unknown name aborts with the full list of valid preset names appended.
Source
Thrown at trendradar/core/scheduler.py:90
# 加载并构建最终 timeline
self.timeline = self._build_timeline(schedule_config, timeline_data)
if self.enabled:
self._validate_timeline(self.timeline)
def _build_timeline(
self,
schedule_config: Dict[str, Any],
timeline_data: Dict[str, Any],
) -> Dict[str, Any]:
"""从 preset 或 custom 构建 timeline"""
preset = schedule_config.get("preset", "always_on")
if preset == "custom":
timeline = copy.deepcopy(timeline_data.get("custom", {}))
else:
presets = timeline_data.get("presets", {})
if preset not in presets:
raise ValueError(
f"未知的预设模板: '{preset}',可选值: "
f"{', '.join(presets.keys())}, custom"
)
timeline = copy.deepcopy(presets[preset])
# 确保 periods 是 dict(可能为空 {})
if timeline.get("periods") is None:
timeline["periods"] = {}
return timeline
def resolve(self) -> ResolvedSchedule:
"""
解析当前时间对应的调度配置
Returns:
ResolvedSchedule 包含当前应执行的行为
"""View on GitHub (pinned to 8ee26026ba)
Solutions
- Use one of the preset names listed in the error message (plus 'custom').
- For a bespoke schedule, set preset: custom and define the custom timeline block.
- After upgrades, re-check the shipped timeline config for newly added presets.
Example fix
# schedule config # before preset: work_hour # typo # after preset: work_hours # exact name from presets map, or 'custom'
Defensive patterns
Strategy: validation
Validate before calling
preset = schedule_config.get("preset", "always_on")
known = set(timeline_data.get("presets", {}).keys()) | {"custom"}
if preset not in known:
raise ValueError(f"unknown preset {preset!r}; valid: {sorted(known)}")
timeline = build_timeline(schedule_config, timeline_data) Type guard
def is_known_preset(name: str, timeline_data: dict) -> bool:
return name == "custom" or name in timeline_data.get("presets", {}) Try / catch
try:
scheduler = Scheduler(schedule_config, timeline_data)
except ValueError as e:
if "未知的预设模板" in str(e):
schedule_config["preset"] = "always_on" # safe default, then rebuild
scheduler = Scheduler(schedule_config, timeline_data)
else:
raise Prevention
- Validate preset names against the presets map before constructing the scheduler.
- Re-validate schedule configs after upgrading trendradar — preset lists change.
When it happens
Trigger: Setting preset: "work_hours" in schedule config when presets only defines e.g. always_on/nightly; typo in the preset name; using a preset introduced in a newer version against an older timeline config that lacks it.
Common situations: Editing config/schedule YAML by hand and misspelling the preset; upgrading trendradar and referencing a newly documented preset with an un-upgraded timeline file; mixing preset names across projects.
Related errors
- 不支持的传输模式: {transport}
- DATA_NOT_FOUND
- timeline 缺少必须字段: {key}
- week_map 缺少星期映射: {day}
- week_map[{day}] 引用了不存在的 day_plan: {plan_key}
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/68756ed883d4c3d2.
Report an issue: GitHub.