Documentation Issue Description
Summary
SimpleDirectoryReader.load_file and SimpleDirectoryReader.aload_file in llama-index-core/llama_index/core/readers/file/base.py repeat the same branching flow (file readers vs raw read, metadata, filename_as_id, error handling). Both call sites include # TODO: make this less redundant (around lines 590 and 660). Consolidate the shared logic so fixes stay in one place and sync/async paths do not drift.
Motivation
Duplicated code tends to get updated in only one path.
Today, sync vs async error handling differs: load_file wraps failures as Exception("Error loading file") from the original exception; aload_file re-raises the original. The refactor should preserve each public entry point’s behavior unless the PR explicitly documents a deliberate alignment and adds tests.
Expected outcome
Less bug surface in file loading.
Simpler reviews and clearer tests for directory/file reading.
Scope (per CONTRIBUTING.md)
Package: llama-index-core only.
Out of scope: new integration packages or unrelated refactors.
Suggested approach
Extract shared logic into private helper(s), parameterized by how content is loaded (load_data vs aload_data).
Keep public method signatures and default behavior stable.
How to validate (from CONTRIBUTING quick start)
Repo root: uv sync (and uv run pre-commit install if you use hooks).
Package dir: cd llama-index-core
Tests: uv run -- pytest
If you change style-sensitive code: from repo root, uv run make lint (and format as you normally do for this repo, e.g. uv run make format if that is your workflow).
Acceptance criteria
load_file and aload_file share one implementation of branching / metadata / ID logic.
Behavior matches pre-refactor unless the PR states otherwise and includes tests for any change.
uv run -- pytest passes in llama-index-core.
uv run make lint passes from repo root when applicable.
References
llama-index-core/llama_index/core/readers/file/base.py — load_file, aload_file
Optional one-liner for the issue list: “Deduplicate SimpleDirectoryReader sync/async file loading; keep behavior; tests + lint per CONTRIBUTING.”
Is this issue right ?or not?
Documentation Issue Description
Summary
SimpleDirectoryReader.load_file and SimpleDirectoryReader.aload_file in llama-index-core/llama_index/core/readers/file/base.py repeat the same branching flow (file readers vs raw read, metadata, filename_as_id, error handling). Both call sites include # TODO: make this less redundant (around lines 590 and 660). Consolidate the shared logic so fixes stay in one place and sync/async paths do not drift.
Motivation
Duplicated code tends to get updated in only one path.
Today, sync vs async error handling differs: load_file wraps failures as Exception("Error loading file") from the original exception; aload_file re-raises the original. The refactor should preserve each public entry point’s behavior unless the PR explicitly documents a deliberate alignment and adds tests.
Expected outcome
Less bug surface in file loading.
Simpler reviews and clearer tests for directory/file reading.
Scope (per CONTRIBUTING.md)
Package: llama-index-core only.
Out of scope: new integration packages or unrelated refactors.
Suggested approach
Extract shared logic into private helper(s), parameterized by how content is loaded (load_data vs aload_data).
Keep public method signatures and default behavior stable.
How to validate (from CONTRIBUTING quick start)
Repo root: uv sync (and uv run pre-commit install if you use hooks).
Package dir: cd llama-index-core
Tests: uv run -- pytest
If you change style-sensitive code: from repo root, uv run make lint (and format as you normally do for this repo, e.g. uv run make format if that is your workflow).
Acceptance criteria
load_file and aload_file share one implementation of branching / metadata / ID logic.
Behavior matches pre-refactor unless the PR states otherwise and includes tests for any change.
uv run -- pytest passes in llama-index-core.
uv run make lint passes from repo root when applicable.
References
llama-index-core/llama_index/core/readers/file/base.py — load_file, aload_file
Optional one-liner for the issue list: “Deduplicate SimpleDirectoryReader sync/async file loading; keep behavior; tests + lint per CONTRIBUTING.”
Is this issue right ?or not?