{"record":{"id":"2af7cd8be5ee9393","repo":"ZhuLinsen/daily_stock_analysis","slug":"context-file-not-found-path","errorCode":null,"errorMessage":"Context file not found: {path}","messagePattern":"Context file not found: (.+?)","errorType":"validation","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"src/services/screening/context.py","lineNumber":329,"sourceCode":"        for source, weight in source_weights.items():\n            text = _safe_context_value(source, max_len=40)\n            if not text:\n                continue\n            try:\n                items.append(f\"{text}={float(weight):.2f}\")\n            except (TypeError, ValueError):\n                continue\n        if items:\n            lines.append(\"来源权重: \" + \"，\".join(items))\n    return \"\\n\".join(lines) if len(lines) > 1 else \"\"\n\n\ndef _read_context_files(paths: list[str | Path]) -> str:\n    chunks: list[str] = []\n    for path_like in paths:\n        path = Path(path_like)\n        if not path.is_file():\n            raise FileNotFoundError(f\"Context file not found: {path}\")\n        text = path.read_text(encoding=\"utf-8\").strip()\n        if text:\n            chunks.append(f\"# {path.name}\\n{text}\")\n    return \"\\n\\n\".join(chunks)\n\n\ndef _read_candidate_context_files(\n    paths: list[str | Path],\n    candidate_df: pd.DataFrame | None,\n) -> str:\n    if not paths or candidate_df is None or candidate_df.empty or \"code\" not in candidate_df.columns:\n        return \"\"\n\n    candidate_names, candidate_order = _candidate_maps(candidate_df)\n    candidate_codes = set(candidate_names)\n    chunks: list[tuple[int, int, str]] = []\n    row_position = 0\n    for path_like in paths:","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/services/screening/context.py#L311-L347","documentation":"FileNotFoundError raised by _read_context_files in the screening context pipeline: every path passed in the context-files list must exist as a regular file, otherwise the screening run aborts. Files are read as UTF-8 text and injected as LLM context, so a missing file is treated as a configuration error rather than being silently skipped.","triggerScenarios":"Running a screening task with context_files=['notes/thesis.md'] where the path is relative to a different working directory, has a typo, or the file was deleted/renamed after config was written. path.is_file() is false for directories too, so pointing at a folder raises the same error.","commonSituations":"Relative paths resolved against a cron/CI working directory instead of the project root; files synced incompletely to a server; absolute paths from another machine left in shared config; passing a directory or glob pattern instead of a file path.","solutions":["Check the path exists from the process's actual cwd (os.getcwd()) — resolve relative paths against an explicit base dir before passing them in.","Fix typos/renames, or re-create the missing file.","If globs are needed, expand them yourself (glob.glob(...)) and pass concrete file paths, filtering out non-files.","If missing context files should be tolerated, pre-filter with Path(p).is_file() before calling, and log a warning for skipped entries."],"exampleFix":"# before\nread_context_files(['notes/thesis.md'])  # FileNotFoundError if cwd differs\n\n# after: resolve against a known base and filter\nbase = Path(__file__).parent\nfiles = [p for p in [base / 'notes/thesis.md'] if p.is_file()]\ntext = _read_context_files(files)","handlingStrategy":"validation","validationCode":"from pathlib import Path\npaths = [Path(p).resolve() for p in context_files]\nmissing = [p for p in paths if not p.is_file()]\nif missing:\n    raise FileNotFoundError(f'context files missing: {missing}')\ntext = _read_context_files(paths)","typeGuard":null,"tryCatchPattern":"try:\n    text = _read_context_files(context_files)\nexcept FileNotFoundError as e:\n    log.warning('skipping missing context file: %s', e)\n    text = ''  # only if context is optional for your run","preventionTips":["Resolve context paths against an explicit base directory, not the process cwd.","Pre-validate all paths with Path.is_file() and report every missing one at once.","Keep context files under version control or a stable artifacts dir to avoid renames breaking runs."],"tags":["screening","context","file-not-found","paths"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}