ZhuLinsen/daily_stock_analysis · error · FileNotFoundError
Candidate context file not found: {path}
Error message
Candidate context file not found: {path} What it means
FileNotFoundError raised by _read_candidate_context_files: every entry in the candidate-context paths list must be an existing regular file before rows are parsed and matched against the screening candidate set. Unlike the main context reader, this runs per screening run with candidate codes; a missing file still aborts immediately.
Source
Thrown at src/services/screening/context.py:350
chunks.append(f"# {path.name}\n{text}")
return "\n\n".join(chunks)
def _read_candidate_context_files(
paths: list[str | Path],
candidate_df: pd.DataFrame | None,
) -> str:
if not paths or candidate_df is None or candidate_df.empty or "code" not in candidate_df.columns:
return ""
candidate_names, candidate_order = _candidate_maps(candidate_df)
candidate_codes = set(candidate_names)
chunks: list[tuple[int, int, str]] = []
row_position = 0
for path_like in paths:
path = Path(path_like)
if not path.is_file():
raise FileNotFoundError(f"Candidate context file not found: {path}")
rows = _load_candidate_context_rows(path)
for row in rows:
code = _normalize_code(row.get("code", row.get("代码", "")))
item = _format_candidate_context_row(row, candidate_codes, candidate_names)
if item:
chunks.append((candidate_order.get(code, len(candidate_order)), row_position, item))
row_position += 1
return "\n".join(item for _, _, item in sorted(chunks))
def _format_candidate_context_rows(
rows: list[dict[str, object]],
candidate_df: pd.DataFrame | None,
) -> str:
if not rows or candidate_df is None or candidate_df.empty or "code" not in candidate_df.columns:
return ""
candidate_names, candidate_order = _candidate_maps(candidate_df)
candidate_codes = set(candidate_names)View on GitHub (pinned to 5159bd72e8)
Solutions
- Verify the upstream stage that generates the candidate context file ran successfully before invoking screening; fix or re-run it.
- Validate all paths up front and fail with a clear message listing which are missing: missing = [p for p in paths if not Path(p).is_file()].
- If some context files are optional, filter them out with a warning instead of passing them through.
- Use explicit, environment-anchored paths (config-resolved absolute paths) rather than relative ones.
Example fix
# before
run_screening(candidates=df, candidate_context=['out/ctx.csv']) # aborts if missing
# after: pre-validate and report all missing at once
missing = [p for p in map(Path, paths) if not p.is_file()]
if missing:
raise FileNotFoundError(f'missing candidate context files: {missing}') Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
missing = [str(p) for p in map(Path, candidate_context_paths) if not p.is_file()]
if missing:
raise FileNotFoundError(f'candidate context files missing (upstream stage failed?): {missing}') Try / catch
try:
ctx = _read_candidate_context_files(paths, candidate_df)
except FileNotFoundError as e:
# a missing artifact means the producer stage failed; re-run it, do not retry this call
log.error('candidate context missing: %s', e)
raise Prevention
- Make the screening run depend on successful completion of the stage that writes candidate context files.
- Pre-check all artifact paths before starting an expensive screening run.
- Use config-resolved absolute paths for pipeline artifacts.
When it happens
Trigger: Passing candidate context paths (CSV/JSON/JSONL files keyed by stock code) where one path does not exist, is a directory, or is a broken symlink. The check happens before any candidate matching, so even unused files in the list abort the run.
Common situations: A pipeline stage that should have produced the candidate context file failed or was skipped, and screening was still invoked with its path; environment-specific output dirs differing between dev and prod; renamed artifacts after a schema change.
Related errors
- Context file not found: {path}
- Unsupported candidate context file format: {path}
- [{self.name}] {stock_code}: {error_reason}
- Unsupported daily source: {source}
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/e8210e4a582fc166.
Report an issue: GitHub.