Skip to content

fix: guard _find_package_dir against missing module paths#44

Open
michaeljabbour wants to merge 1 commit intomicrosoft:mainfrom
michaeljabbour:fix/loader-guard-missing-module-path
Open

fix: guard _find_package_dir against missing module paths#44
michaeljabbour wants to merge 1 commit intomicrosoft:mainfrom
michaeljabbour:fix/loader-guard-missing-module-path

Conversation

@michaeljabbour
Copy link

Summary

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

Root 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_dir at the iterdir() fallback.

Test Plan

  • 7 new tests in tests/test_loader.py covering:
    • Non-existent path returns None (core regression)
    • No FileNotFoundError raised (anti-regression)
    • Hash-style cache path pattern handled
    • Empty directory returns None
    • Happy path still works
    • Caller produces ModuleValidationError (not FileNotFoundError)
    • Error message includes module ID and path

🤖 Generated with Amplifier

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant