sansan0/TrendRadar · critical · FileNotFoundError
配置文件 {config_path} 不存在
Error message
配置文件 {config_path} 不存在 What it means
Raised by trendradar's config loader when the resolved config file does not exist. Path resolution order: explicit config_path argument, then CONFIG_PATH env var, then default config/config.yaml. It fails fast with FileNotFoundError before any YAML parsing.
Source
Thrown at trendradar/core/loader.py:541
def load_config(config_path: Optional[str] = None) -> Dict[str, Any]:
"""
加载配置文件
Args:
config_path: 配置文件路径,默认从环境变量 CONFIG_PATH 获取或使用 config/config.yaml
Returns:
包含所有配置的字典
Raises:
FileNotFoundError: 配置文件不存在
"""
if config_path is None:
config_path = os.environ.get("CONFIG_PATH", "config/config.yaml")
if not Path(config_path).exists():
raise FileNotFoundError(f"配置文件 {config_path} 不存在")
with open(config_path, "r", encoding="utf-8") as f:
config_data = yaml.safe_load(f)
print(f"配置文件加载成功: {config_path}")
# 合并所有配置
config = {}
# 应用配置
config.update(_load_app_config(config_data))
# 爬虫配置
config.update(_load_crawler_config(config_data))
# 报告配置
config.update(_load_report_config(config_data))
View on GitHub (pinned to 8ee26026ba)
Solutions
- Create or restore the config file at the path shown in the error message.
- Set CONFIG_PATH to an absolute path: export CONFIG_PATH=/etc/trendradar/config.yaml.
- Or pass the path explicitly to the load function if calling it programmatically.
- For services, set the unit's WorkingDirectory to the repo root so config/config.yaml resolves.
Example fix
# before: CONFIG_PATH unset, cwd=/srv -> looks for /srv/config/config.yaml # after: export CONFIG_PATH=/opt/trendradar/config/config.yaml
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
config_path = Path(os.environ.get("CONFIG_PATH", "config/config.yaml"))
if not config_path.is_file():
raise SystemExit(f"missing config: {config_path}; set CONFIG_PATH")
config = load_config(str(config_path)) Try / catch
try:
config = load_config()
except FileNotFoundError as e:
print(f"{e}. Copy config/config.example.yaml to config/config.yaml and retry.")
raise SystemExit(1) Prevention
- Set CONFIG_PATH to an absolute path, especially under systemd (also set WorkingDirectory).
- Add a startup check that all required config files exist before doing work.
- Ship an example config and document the copy step.
When it happens
Trigger: Launching trendradar without config/config.yaml present; CONFIG_PATH pointing to a deleted or misspelled file; running from a cwd where the relative default path does not resolve.
Common situations: New deployment missing the config directory; CONFIG_PATH left over from an old install pointing at a removed location; running as a service/systemd unit whose WorkingDirectory differs from the repo root, breaking the relative default.
Related errors
- 频率词文件 {frequency_file} 不存在
- 不支持的传输模式: {transport}
- DATA_NOT_FOUND
- 不支持的模式: {mode}。支持的模式: daily, current
- CRAWL_TASK_ERROR
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/f9236ca8d5389c3c.
Report an issue: GitHub.