{"record":{"id":"832e27a04753af60","repo":"run-llama/llama_index","slug":"file-type-not-supported-file-path","errorCode":null,"errorMessage":"File type not supported: {file_path}","messagePattern":"File type not supported: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/command_line/upgrade.py","lineNumber":272,"sourceCode":"    installed_modules = [\"llama-index-core\"]  # default installs\n    new_lines, new_installs = parse_lines(lines, installed_modules)\n\n    with open(file_path, \"w\", encoding=\"utf-8\") as f:\n        f.write(\"\".join(new_lines))\n\n    if len(new_installs) > 0:\n        print(\"New installs:\")\n    for install in new_installs:\n        print(install.strip().replace(\"%\", \"\"))\n\n\ndef upgrade_file(file_path: str) -> None:\n    if file_path.endswith(\".ipynb\"):\n        upgrade_nb_file(file_path)\n    elif file_path.endswith((\".py\", \".md\")):\n        upgrade_py_md_file(file_path)\n    else:\n        raise Exception(f\"File type not supported: {file_path}\")\n\n\ndef _is_hidden(path: Path) -> bool:\n    return any(part.startswith(\".\") and part not in [\".\", \"..\"] for part in path.parts)\n\n\ndef upgrade_dir(input_dir: str) -> None:\n    file_refs = list(Path(input_dir).rglob(\"*.py\"))\n    file_refs += list(Path(input_dir).rglob(\"*.ipynb\"))\n    file_refs += list(Path(input_dir).rglob(\"*.md\"))\n    file_refs = [x for x in file_refs if not _is_hidden(x)]\n    for file_ref in file_refs:\n        if file_ref.is_file():\n            upgrade_file(str(file_ref))\n","sourceCodeStart":254,"sourceCodeEnd":287,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/command_line/upgrade.py#L254-L287","documentation":"The `llama-index-cli upgrade` command rewrites files that use the old llama_index -> llama_index.core import paths, but upgrade_file() only handles three extensions: .ipynb (upgrade_nb_file), and .py/.md (upgrade_py_md_file). Any other extension raises a generic Exception listing the path.","triggerScenarios":"Running `llama-index-cli upgrade <file>` (or upgrade_file(path) programmatically) on a file whose extension is not .py, .md, or .ipynb — e.g. .pyw, .txt, .rst, .jmd, or a file with no extension.","commonSituations":"Pointing the migration CLI at a directory entry or scratch file with an unusual extension; passing a Jupyter notebook saved as .json; shell globs that accidentally match non-source files.","solutions":["Only run the upgrade command on .py, .md, or .ipynb files","Rename or copy the file to a supported extension first (e.g. script.txt -> script.py) if it really contains Python","Use upgrade_dir() on a directory — it rglobs only *.py, *.ipynb and *.md, skipping unsupported files for you"],"exampleFix":"// before\n$ llama-index-cli upgrade notes.txt\nException: File type not supported: notes.txt\n\n// after\n$ cp notes.txt notes.md && llama-index-cli upgrade notes.md\n# or upgrade a whole directory (only .py/.md/.ipynb are touched):\n$ llama-index-cli upgrade-dir ./my_project","handlingStrategy":"validation","validationCode":"from pathlib import Path\nSUPPORTED = {\".py\", \".md\", \".ipynb\"}\nif Path(file_path).suffix not in SUPPORTED:\n    raise ValueError(f\"unsupported: {file_path}; expected one of {SUPPORTED}\")","typeGuard":"from pathlib import Path\n\ndef is_upgradeable(path: str) -> bool:\n    return Path(path).suffix in {\".py\", \".md\", \".ipynb\"}","tryCatchPattern":"from llama_index.core.command_line.upgrade import upgrade_file\ntry:\n    upgrade_file(path)\nexcept Exception as e:\n    if \"File type not supported\" in str(e):\n        print(f\"skipping {path}: not a .py/.md/.ipynb file\")\n    else:\n        raise","preventionTips":["Filter file lists by suffix before invoking the upgrade CLI","Prefer upgrade_dir() which already globs only supported extensions","Note it raises bare Exception, so catch Exception and match the message"],"tags":["cli","migration","file-format","upgrade"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}