{"record":{"id":"fe0110847a703f92","repo":"sansan0/TrendRadar","slug":"frequency-file","errorCode":null,"errorMessage":"频率词文件 {frequency_file} 不存在","messagePattern":"频率词文件 (.+?) 不存在","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"trendradar/core/frequency.py","lineNumber":134,"sourceCode":"    Returns:\n        (词组列表, 词组内过滤词, 全局过滤词)\n\n    Raises:\n        FileNotFoundError: 频率词文件不存在\n    \"\"\"\n    if frequency_file is None:\n        frequency_file = os.environ.get(\n            \"FREQUENCY_WORDS_PATH\", \"config/frequency_words.txt\"\n        )\n\n    frequency_path = Path(frequency_file)\n    if not frequency_path.exists():\n        # 尝试作为短文件名，拼接 config/custom/keyword/ 前缀\n        custom_path = Path(\"config/custom/keyword\") / frequency_file\n        if custom_path.exists():\n            frequency_path = custom_path\n        else:\n            raise FileNotFoundError(f\"频率词文件 {frequency_file} 不存在\")\n\n    with open(frequency_path, \"r\", encoding=\"utf-8\") as f:\n        content = f.read()\n\n    word_groups = [group.strip() for group in content.split(\"\\n\\n\") if group.strip()]\n\n    processed_groups = []\n    filter_words = []\n    global_filters = []\n\n    # 默认区域（向后兼容）\n    current_section = \"WORD_GROUPS\"\n\n    for group in word_groups:\n        # 过滤空行和注释行（# 开头）\n        lines = [line.strip() for line in group.split(\"\\n\") if line.strip() and not line.strip().startswith(\"#\")]\n\n        if not lines:","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/trendradar/core/frequency.py#L116-L152","documentation":"Raised by the frequency-word loader when neither the configured frequency file path nor the fallback under config/custom/keyword/ exists. The loader resolves the path from the argument, then FREQUENCY_WORDS_PATH env var, then config/frequency_words.txt, and finally tries the short-name fallback before giving up with FileNotFoundError.","triggerScenarios":"Setting FREQUENCY_WORDS_PATH to a moved/renamed file; deleting config/frequency_words.txt without replacing it; running trendradar from a directory where the relative config path does not resolve (cwd not repo root).","commonSituations":"Fresh clone missing the config file (not committed or generated by setup); deployment where the service starts in a different cwd so relative 'config/frequency_words.txt' points nowhere; renaming a custom keyword file but leaving the env var stale.","solutions":["Verify the file exists at the exact path in the error; create or restore it.","If unset intentionally, ensure config/frequency_words.txt exists in the working directory, or set FREQUENCY_WORDS_PATH to an absolute path.","For short filenames, place the file under config/custom/keyword/<name> so the fallback finds it.","Run from the repository root so relative config paths resolve."],"exampleFix":"# before: FREQUENCY_WORDS_PATH=/old/path/frequency_words.txt (file moved)\n# after:\nexport FREQUENCY_WORDS_PATH=/abs/path/to/config/frequency_words.txt","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef resolve_frequency_file(p=None):\n    cand = Path(p or os.environ.get(\"FREQUENCY_WORDS_PATH\", \"config/frequency_words.txt\"))\n    if cand.exists():\n        return cand\n    alt = Path(\"config/custom/keyword\") / cand.name\n    if alt.exists():\n        return alt\n    raise FileNotFoundError(f\"frequency file missing: {cand} and {alt}\")\n\nfreq = resolve_frequency_file()  # call before load_frequency_words","typeGuard":null,"tryCatchPattern":"try:\n    words = load_frequency_words()\nexcept FileNotFoundError as e:\n    logging.warning(f\"{e}; falling back to default config/frequency_words.txt\")\n    words = load_frequency_words(\"config/frequency_words.txt\")","preventionTips":["Set FREQUENCY_WORDS_PATH to an absolute path in deployment.","Include the frequency words file in deployment artifacts / setup scripts.","Health-check required config files at process start."],"tags":["config","file-not-found","frequency-words","environment"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}