fix: guard _find_package_dir against missing module paths#44
Open
michaeljabbour wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: guard _find_package_dir against missing module paths#44michaeljabbour wants to merge 1 commit intomicrosoft:mainfrom
michaeljabbour wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When a module's cache directory is missing (e.g., never cloned), _find_package_dir() calls iterdir() on a non-existent path, causing an unhandled FileNotFoundError that crashes session initialization. - Add existence check at the top of _find_package_dir() — returns None when module_path doesn't exist - The caller (_validate_module) already handles None by raising a clear ModuleValidationError - Converts an opaque FileNotFoundError crash into an actionable error message 🤖 Generated with Amplifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a module's cache directory is missing (e.g., never cloned),
_find_package_dir()callsiterdir()on a non-existent path, causing an unhandledFileNotFoundErrorthat crashes session initialization._find_package_dir()— returnsNonewhenmodule_pathdoesn't exist_validate_module) already handlesNoneby raising a clearModuleValidationErrorFileNotFoundErrorcrash into an actionable error messageRoot Cause
The source resolver computes expected cache paths via
sha256(url)[:16]and returns them without verifying the directory exists. When a module's cache entry is missing (e.g., local bundles whose git-sourced modules weren't pre-cached), the loader crashes in_find_package_dirat theiterdir()fallback.Test Plan
tests/test_loader.pycovering:None(core regression)FileNotFoundErrorraised (anti-regression)NoneModuleValidationError(notFileNotFoundError)🤖 Generated with Amplifier