{"record":{"id":"ff4a24431bfdc966","repo":"MiniMax-AI/skills","slug":"file-not-found-file-path","errorCode":null,"errorMessage":"File not found: {file_path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"skills/minimax-xlsx/scripts/xlsx_reader.py","lineNumber":46,"sourceCode":"# ---------------------------------------------------------------------------\n\ndef detect_and_load(file_path: str, sheet_name_filter: str | None = None) -> dict:\n    \"\"\"\n    Load file into {sheet_name: DataFrame} dict.\n    CSV/TSV files are mapped to a single-key dict using the file stem as key.\n\n    Raises ValueError for unsupported formats or encoding failures.\n    \"\"\"\n    try:\n        import pandas as pd\n    except ImportError:\n        raise RuntimeError(\n            \"pandas is not installed. Run: pip install pandas openpyxl\"\n        )\n\n    path = Path(file_path)\n    if not path.exists():\n        raise FileNotFoundError(f\"File not found: {file_path}\")\n\n    suffix = path.suffix.lower()\n\n    if suffix in (\".xlsx\", \".xlsm\"):\n        target = sheet_name_filter if sheet_name_filter else None\n        result = pd.read_excel(file_path, sheet_name=target)\n        # pd.read_excel with sheet_name=None returns dict; with a name, returns DataFrame\n        if isinstance(result, dict):\n            return result\n        else:\n            return {sheet_name_filter: result}\n\n    elif suffix in (\".csv\", \".tsv\"):\n        sep = \"\\t\" if suffix == \".tsv\" else \",\"\n        encodings = [\"utf-8-sig\", \"gbk\", \"utf-8\", \"latin-1\"]\n        last_error = None\n        for enc in encodings:\n            try:","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/minimax-xlsx/scripts/xlsx_reader.py#L28-L64","documentation":"detect_and_load() checks path.exists() after the pandas import and raises FileNotFoundError with the given path. It is caught in main() and reported as exit code 1.","triggerScenarios":"Passing a path that does not exist on disk — typo, relative path from the wrong working directory, or a file that was not yet downloaded/created.","commonSituations":"Wrong working directory; case-sensitivity mismatch on Linux; path with a trailing space or stray quote; file deleted/moved between runs.","solutions":["Verify the path exists: ls -la <file>","Use an absolute path.","Check spelling and case exactly (Linux is case-sensitive)."],"exampleFix":"# before\npython3 xlsx_reader.py data.xlsx   # FileNotFoundError\n\n# after\npython3 xlsx_reader.py /abs/path/to/data.xlsx","handlingStrategy":"validation","validationCode":"from pathlib import Path\nif not Path(file_path).is_file():\n    raise FileNotFoundError(f'File not found: {file_path}')","typeGuard":"def is_readable_file(p) -> bool:\n    from pathlib import Path\n    pp = Path(p)\n    return pp.is_file() and os.access(pp, os.R_OK)","tryCatchPattern":"try:\n    sheets = detect_and_load(file_path)\nexcept FileNotFoundError as e:\n    print(f'ERROR: {e}', file=sys.stderr)\n    sys.exit(1)","preventionTips":["Resolve to an absolute path before calling.","Check Path.is_file() (not just exists) to reject directories.","Validate read permission with os.access on shared/CI filesystems."],"tags":["filesystem","validation","python"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}