{"record":{"id":"f9236ca8d5389c3c","repo":"sansan0/TrendRadar","slug":"config-path","errorCode":null,"errorMessage":"配置文件 {config_path} 不存在","messagePattern":"配置文件 (.+?) 不存在","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"critical","filePath":"trendradar/core/loader.py","lineNumber":541,"sourceCode":"\ndef load_config(config_path: Optional[str] = None) -> Dict[str, Any]:\n    \"\"\"\n    加载配置文件\n\n    Args:\n        config_path: 配置文件路径，默认从环境变量 CONFIG_PATH 获取或使用 config/config.yaml\n\n    Returns:\n        包含所有配置的字典\n\n    Raises:\n        FileNotFoundError: 配置文件不存在\n    \"\"\"\n    if config_path is None:\n        config_path = os.environ.get(\"CONFIG_PATH\", \"config/config.yaml\")\n\n    if not Path(config_path).exists():\n        raise FileNotFoundError(f\"配置文件 {config_path} 不存在\")\n\n    with open(config_path, \"r\", encoding=\"utf-8\") as f:\n        config_data = yaml.safe_load(f)\n\n    print(f\"配置文件加载成功: {config_path}\")\n\n    # 合并所有配置\n    config = {}\n\n    # 应用配置\n    config.update(_load_app_config(config_data))\n\n    # 爬虫配置\n    config.update(_load_crawler_config(config_data))\n\n    # 报告配置\n    config.update(_load_report_config(config_data))\n","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/trendradar/core/loader.py#L523-L559","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: CONFIG_PATH unset, cwd=/srv -> looks for /srv/config/config.yaml\n# after:\nexport CONFIG_PATH=/opt/trendradar/config/config.yaml","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nconfig_path = Path(os.environ.get(\"CONFIG_PATH\", \"config/config.yaml\"))\nif not config_path.is_file():\n    raise SystemExit(f\"missing config: {config_path}; set CONFIG_PATH\")\nconfig = load_config(str(config_path))","typeGuard":null,"tryCatchPattern":"try:\n    config = load_config()\nexcept FileNotFoundError as e:\n    print(f\"{e}. Copy config/config.example.yaml to config/config.yaml and retry.\")\n    raise SystemExit(1)","preventionTips":["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."],"tags":["config","file-not-found","yaml","environment"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}