{"record":{"id":"43d0b09659196276","repo":"sansan0/TrendRadar","slug":"crawl-task-error","errorCode":"CRAWL_TASK_ERROR","errorMessage":"配置文件不存在","messagePattern":"配置文件不存在","errorType":"error_code","errorClass":"CrawlTaskError","httpStatus":null,"severity":"critical","filePath":"mcp_server/tools/system.py","lineNumber":78,"sourceCode":"                \"success\": False,\n                \"error\": e.to_dict()\n            }\n        except Exception as e:\n            return {\n                \"success\": False,\n                \"error\": {\n                    \"code\": \"INTERNAL_ERROR\",\n                    \"message\": str(e)\n                }\n            }\n\n    def _load_crawl_config(self):\n        \"\"\"加载爬取配置，返回 (config_data, target_platforms_config)\"\"\"\n        import yaml\n\n        config_path = self.project_root / \"config\" / \"config.yaml\"\n        if not config_path.exists():\n            raise CrawlTaskError(\n                \"配置文件不存在\",\n                suggestion=f\"请确保配置文件存在: {config_path}\"\n            )\n\n        with open(config_path, \"r\", encoding=\"utf-8\") as f:\n            config_data = yaml.safe_load(f)\n\n        platforms_config = config_data.get(\"platforms\", {})\n        if not platforms_config.get(\"enabled\", True):\n            raise CrawlTaskError(\n                \"热榜平台已禁用\",\n                suggestion=\"请检查 config/config.yaml 中的 platforms.enabled 配置\"\n            )\n        all_platforms = [p for p in platforms_config.get(\"sources\", []) if p.get(\"enabled\", True)]\n        if not all_platforms:\n            raise CrawlTaskError(\n                \"配置文件中没有平台配置\",\n                suggestion=\"请检查 config/config.yaml 中的 platforms.sources 配置\"","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/tools/system.py#L60-L96","documentation":"Thrown by _load_crawl_config in the system tools when config/config.yaml does not exist under project_root. This is a hard prerequisite: the hot-list crawl tasks read platform definitions, credentials, and feature toggles from this file before doing anything else.","triggerScenarios":"Running a crawl-trigger MCP tool in a checkout where config/config.yaml was never created (usually it is gitignored and must be copied from an example), or when project_root is mis-detected (launched from a different working directory).","commonSituations":"Fresh clone without running the setup step that copies config.example.yaml; deploying a container without mounting the config directory; CWD-dependent project_root resolution.","solutions":["Create config/config.yaml under the project root (copy from the repo's example config if provided)","Verify project_root points at the actual repository when launching the MCP server from another directory","In deployments, mount/bake the config file into the image or volume"],"exampleFix":"# before: file missing\n# $ ls config/\n# (empty)\n\n# after\n cp config/config.example.yaml config/config.yaml\n # then edit platforms/credential entries","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef crawl_config_ready(project_root: Path) -> bool:\n    return (project_root / \"config\" / \"config.yaml\").is_file()\n\nif not crawl_config_ready(PROJECT_ROOT):\n    raise RuntimeError(\"config/config.yaml missing — run setup first\")","typeGuard":"def is_existing_file(p) -> bool:\n    from pathlib import Path\n    try:\n        return Path(p).is_file()\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    run_crawl_task()\nexcept CrawlTaskError as e:\n    if \"配置文件不存在\" in str(e):\n        # deployment issue: surface to operator, do not retry blindly\n        raise RuntimeError(f\"crawl config missing at {e.suggestion}\") from e\n    raise","preventionTips":["Add a startup preflight check that config/config.yaml exists before serving crawl tools","Keep config.example.yaml in VCS and a setup step that copies it","Mount the config directory explicitly in containers; run a healthcheck on the file"],"tags":["config","deployment","crawl"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}