{"record":{"id":"7410e9b84e322bef","repo":"run-llama/llama_index","slug":"error-loading-file","errorCode":null,"errorMessage":"Error loading file","messagePattern":"Error loading file","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/readers/file/base.py","lineNumber":620,"sourceCode":"            if file_suffix not in file_extractor:\n                # instantiate file reader if not already\n                reader_cls = default_file_reader_cls[file_suffix]\n                file_extractor[file_suffix] = reader_cls()\n            reader = file_extractor[file_suffix]\n\n            # load data -- catch all errors except for ImportError\n            try:\n                kwargs: dict[str, Any] = {\"extra_info\": metadata}\n                if fs and not is_default_fs(fs):\n                    kwargs[\"fs\"] = fs\n                docs = reader.load_data(input_file, **kwargs)\n            except ImportError as e:\n                # ensure that ImportError is raised so user knows\n                # about missing dependencies\n                raise ImportError(str(e))\n            except Exception as e:\n                if raise_on_error:\n                    raise Exception(\"Error loading file\") from e\n                # otherwise, just skip the file and report the error\n                print(\n                    f\"Failed to load file {input_file} with error: {e}. Skipping...\",\n                    flush=True,\n                )\n                return []\n\n            # iterate over docs if needed\n            if filename_as_id:\n                for i, doc in enumerate(docs):\n                    doc.id_ = f\"{input_file!s}_part_{i}\"\n\n            documents.extend(docs)\n        else:\n            # do standard read\n            fs = fs or get_default_fs()\n            with fs.open(input_file, errors=errors, encoding=encoding) as f:\n                data = cast(bytes, f.read()).decode(encoding, errors=errors)","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/readers/file/base.py#L602-L638","documentation":"Raised by SimpleDirectoryReader._load_data when reader.load_data(input_file, ...) throws a non-ImportError exception and raise_on_error=True. The loader converts any per-file failure (corrupt file, bad encoding, missing parser output) into a generic Exception chained from the original via `raise Exception(\"Error loading file\") from e`; use __cause__ to see the real error. With raise_on_error=False the file is instead skipped with a printed message.","triggerScenarios":"Ingesting a corrupt or truncated PDF/DOCX; a file whose bytes do not match its extension; a parser dependency (e.g. pypdf, docx2txt) throwing at runtime rather than at import; raise_on_error=True passed to the constructor while the corpus contains a few bad files.","commonSituations":"Bulk ingestion of user-uploaded documents where some are malformed; partially downloaded files; files with wrong extensions; mixed-quality corpora scraped from the web.","solutions":["Inspect the chained cause: catch the exception and print exc.__cause__ to find the real per-file error.","Test the failing file in isolation: SimpleDirectoryReader(input_files=[bad_file]).load_data() to reproduce without the rest of the corpus.","Re-save or repair the offending document (re-export the PDF/DOCX) or remove it from the directory.","For tolerant bulk ingestion, construct SimpleDirectoryReader(..., raise_on_error=False) so bad files are skipped and reported instead of aborting."],"exampleFix":"# before\nreader = SimpleDirectoryReader(input_dir=\"./data\", raise_on_error=True)\ndocs = reader.load_data()  # aborts on first bad file\n\n# after\ntry:\n    docs = SimpleDirectoryReader(input_dir=\"./data\").load_data()\nexcept Exception as e:\n    print(\"real cause:\", e.__cause__)\n# or skip bad files wholesale:\nreader = SimpleDirectoryReader(input_dir=\"./data\", raise_on_error=False)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    docs = reader.load_data()\nexcept Exception as e:\n    raise RuntimeError(f\"load failed, cause: {e.__cause__}\") from e","preventionTips":["Use raise_on_error=False for bulk ingestion of untrusted files.","Always inspect the chained __cause__, not the generic message.","Test suspicious files individually with input_files=[...]."],"tags":["file-parsing","error-handling","directory-reader","chained-exception"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}