Skip to content

Commit 73a0767

Browse files
author
johnhuang316
committed
Refactor: Improve file_index structure to prevent KeyError
This commit refactors the internal `file_index` data structure to be more explicit and robust, preventing a `KeyError` crash in the `find_files` tool. Previously, the `file_index` was inconsistent: file entries were marked with "type": "file", but directory entries were implicitly represented by a plain dictionary, lacking a `type` key. This led to errors in functions like `_get_all_files` that incorrectly assumed the `type` key would always be present. This has been resolved by: - Modifying `_index_project` to explicitly add {"type": "directory", "children": {}} for all directory entries. - Updating the helper functions (`_get_all_files`, `_count_files`) to correctly parse this new, consistent structure. - Adding backward-compatibility in `set_project_path` to handle old-format index files by gracefully triggering a re-index if loading fails. This change makes the indexing logic more maintainable and less prone to errors. Fixes the first part of #10.
1 parent 141b017 commit 73a0767

File tree

1 file changed

+784
-778
lines changed

1 file changed

+784
-778
lines changed

0 commit comments

Comments
 (0)