{"record":{"id":"b546812469601d38","repo":"anthropics/financial-services","slug":"file-not-found-excel-path-b54681","errorCode":null,"errorMessage":"File not found: {excel_path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"plugins/vertical-plugins/financial-analysis/skills/dcf-model/scripts/validate_dcf.py","lineNumber":26,"sourceCode":"import json\nfrom pathlib import Path\nfrom typing import Optional\n\n\nclass DCFModelValidator:\n    \"\"\"Validates DCF models for errors and quality issues\"\"\"\n\n    def __init__(self, excel_path: str):\n        try:\n            import openpyxl\n        except ImportError:\n            raise ImportError(\"openpyxl not installed. Run: pip install openpyxl\")\n\n        self.excel_path = excel_path\n        self.openpyxl = openpyxl\n\n        if not Path(excel_path).exists():\n            raise FileNotFoundError(f\"File not found: {excel_path}\")\n\n        self.workbook_formulas = openpyxl.load_workbook(excel_path, data_only=False)\n        self.workbook_values = openpyxl.load_workbook(excel_path, data_only=True)\n        self.errors = []\n        self.warnings = []\n        self.info = []\n        \n    def validate_all(self) -> dict:\n        \"\"\"\n        Run all validation checks\n\n        Returns:\n            Dict with validation results\n        \"\"\"\n        from datetime import datetime\n\n        self.check_sheet_structure()\n        self.check_formula_errors()","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/anthropics/financial-services/blob/69cbc81467a5dced793eee03dec4658aa24ef856/plugins/vertical-plugins/financial-analysis/skills/dcf-model/scripts/validate_dcf.py#L8-L44","documentation":"Raised in DCFModelValidator.__init__ of the vertical-plugins (financial-analysis) source copy of validate_dcf.py when Path(excel_path).exists() returns False. The check runs before openpyxl.load_workbook, so the validator never attempts to open a nonexistent workbook. At runtime the message contains the literal path that was passed in.","triggerScenarios":"Calling DCFModelValidator(excel_path) where excel_path points to a missing file: wrong CWD for a relative path, typo, wrong case on a case-sensitive FS, or a model that an upstream export/generation step never wrote. The message interpolates the exact constructor argument.","commonSituations":"Automation that generates a DCF into a temp/output dir and validates from a different CWD; batch scripts looping over filenames where one is absent; paths quoted or whitespace-padded from CLI args or agent output; files deleted by concurrent cleanup before validation runs.","solutions":["Verify from the script's working directory: ls -l '<path>'; fix the path or CWD accordingly","Normalize to an absolute path: DCFModelValidator(str(Path(raw).resolve()))","Clean paths from external sources: raw.strip().strip('\"\\'') and expand ~ with Path.expanduser()","If the file should have been generated upstream, inspect that step's output/logs to find where it was actually written"],"exampleFix":"# before\nvalidator = DCFModelValidator('exports/dcf_final.xlsx')  # FileNotFoundError\n\n# after\nfrom pathlib import Path\np = Path('exports/dcf_final.xlsx').expanduser().resolve()\nif not p.is_file():\n    raise SystemExit(f'Missing model file: {p}')\nvalidator = DCFModelValidator(str(p))","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(excel_path).expanduser().resolve()\nif not p.is_file():\n    raise SystemExit(f'Model file not found: {p}')\nvalidator = DCFModelValidator(str(p))","typeGuard":"def is_valid_model_path(raw: str) -> bool:\n    p = Path(raw).expanduser()\n    return p.is_file() and p.suffix.lower() in {'.xlsx', '.xlsm'}","tryCatchPattern":"try:\n    validator = DCFModelValidator(path)\nexcept FileNotFoundError as e:\n    raise SystemExit(f'Could not open model: {e}. Verify the path and that the upstream export produced the file.')","preventionTips":["Use absolute, resolved paths in automated pipelines","Validate user/agent-supplied paths (existence + .xlsx extension) before use","After any export step, assert the output file exists and log its resolved path"],"tags":["python","file-not-found","path","filesystem","excel"],"backgroundTag":"file-not-found","analyzedSha":"69cbc81467a5dced793eee03dec4658aa24ef856","analyzedAt":"2026-08-27T12:38:04.061Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}