{"record":{"id":"5ad100c405f3565f","repo":"anthropics/financial-services","slug":"file-not-found-excel-path","errorCode":null,"errorMessage":"File not found: {excel_path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"plugins/agent-plugins/model-builder/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/agent-plugins/model-builder/skills/dcf-model/scripts/validate_dcf.py#L8-L44","documentation":"Raised in DCFModelValidator.__init__ when Path(excel_path).exists() is False, i.e. the Excel file the validator was asked to inspect does not exist on disk. It fires before any workbook loading (openpyxl.load_workbook is only called after this check) so no partial state is created. The path in the message is echoed verbatim from the constructor argument.","triggerScenarios":"Calling DCFModelValidator(excel_path) with a wrong relative path (relative to the process CWD, not the script), a filename typo, a path to a file on another machine/share, or a file that an upstream step (e.g. an export or generation step) failed to produce. Only the message template is shown here; the actual error interpolates the given path.","commonSituations":"Agent/skill workflows where the model file is generated in a temp dir but validated from a different CWD; case-sensitive filesystems (Model.XLSX vs model.xlsx); Windows path separators passed on POSIX or vice versa; trailing quotes/whitespace in paths parsed from CLI args or LLM output; files cleaned up by a temp-dir cleanup race.","solutions":["Check the file exists from the same CWD the script runs in: ls -l '<path>' or Path(path).resolve() and print it before constructing the validator","Use an absolute path: DCFModelValidator(str(Path('model.xlsx').resolve()))","If the path comes from CLI/LLM output, strip whitespace and quotes before passing it","If an upstream step was supposed to create the file, verify that step succeeded and where it wrote output (check its logs/temp dir)"],"exampleFix":"# before\nvalidator = DCFModelValidator('models/dcf.xlsx')  # FileNotFoundError\n\n# after\nfrom pathlib import Path\np = Path('models/dcf.xlsx').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}. Check the path and that the export step produced the file.')","preventionTips":["Pass absolute resolved paths (Path(x).resolve()) instead of CWD-relative ones","Validate paths from CLI/LLM input: strip whitespace/quotes before use","When chaining generate-then-validate steps, assert the output file exists immediately after generation"],"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"}