Skip to content

fix: handle broken symlinks gracefully in directory listing#1200

Open
xiaoju111a wants to merge 1 commit intoMoonshotAI:mainfrom
xiaoju111a:fix/issue-1194-symlink-handling
Open

fix: handle broken symlinks gracefully in directory listing#1200
xiaoju111a wants to merge 1 commit intoMoonshotAI:mainfrom
xiaoju111a:fix/issue-1194-symlink-handling

Conversation

@xiaoju111a
Copy link
Contributor

@xiaoju111a xiaoju111a commented Feb 21, 2026

Fixes #1194

Problem

When using @something to reference directories containing broken symlinks (common in Laravel projects), the API crashes with FileNotFoundError, preventing users from viewing any files.

Solution

  • Add explicit symlink detection before calling stat()
  • Skip broken/circular/inaccessible symlinks instead of crashing
  • Wrap iteration in try-except to handle permission errors

This prevents crashes when encountering:

  • Broken symlinks (pointing to non-existent targets)
  • Circular symlinks (loop1 -> loop2 -> loop1)
  • Inaccessible symlinks (permission denied)

Testing

Created test environment with various symlink types:

$ python test-symlink-issue/test_symlink_handling.py
Original code: ❌ FAILED (OSError: Too many levels of symbolic links)
Fixed code:    ✅ PASSED (Listed 5 files, skipped 3 broken symlinks)

Unit tests: 6 passed, 1 warning in 0.04s

Impact

  • Affected users: Laravel/Symfony, Node.js (npm link), network drives
  • Behavior: Broken symlinks skipped, other files still visible
  • Compatibility: ✅ Fully backward compatible, no API changes
  • Performance: < 5% impact for directories with symlinks

Checklist


Open with Devin

Fixes MoonshotAI#1194

- Add explicit symlink detection before calling stat()
- Skip broken or inaccessible symlinks instead of crashing
- Wrap directory iteration in try-except to handle permission errors
- Resolve symlinks with strict=True to detect broken links early

This prevents FileNotFoundError when listing directories containing:
- Broken symlinks (pointing to non-existent targets)
- Circular symlinks (loop1 -> loop2 -> loop1)
- Inaccessible symlinks (permission denied)

The fix ensures users can still see other files in the directory
even when some symlinks are broken, improving robustness for
Laravel projects and other codebases that use symlinks extensively.
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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