Repository navigation
fix(runtime): skip unreadable Windows drives - #11421
Conversation
Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| it('skips an unreadable drive with an unexpected errno and logs it', async () => { | ||
| const error = Object.assign(new Error('EIO'), { code: 'EIO' }) | ||
| const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined) | ||
| const statPath = async (p: string): Promise<Stats> => { | ||
| if (p === 'D:\\') { | ||
| throw Object.assign(new Error(code), { code }) | ||
| throw error | ||
| } | ||
| throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' }) | ||
| } | ||
|
|
||
| await expect(listWindowsDrives(statPath)).rejects.toMatchObject({ code }) | ||
| const result = await listWindowsDrives(statPath) | ||
|
|
||
| expect(result.entries).toEqual([]) | ||
| expect(warn).toHaveBeenCalledOnce() | ||
| expect(warn).toHaveBeenCalledWith('[windows-drive-listing] Failed to stat drive', { | ||
| root: 'D:\\', | ||
| error | ||
| }) | ||
| }) |
There was a problem hiding this comment.
EMFILE systemic-error path now untested and silently swallowed
The old it.each(['EIO', 'EMFILE']) test was intentionally named "surfaces systemic failures" — it encoded the design decision that EMFILE (too many open file descriptors) is a system-wide resource-exhaustion signal that callers should see as an exception rather than an empty drive list. The new code swallows EMFILE with console.warn just like a per-drive EIO. If the OS is truly out of file descriptors while all 26 stat calls run concurrently, the function returns an empty entries array and emits 26 warnings; the caller has no way to distinguish "no drives mounted" from "fd exhaustion prevented discovery." Adding an EMFILE-specific test for the new behaviour (and deciding whether it should remain a thrown error) would make the changed contract explicit.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Greptile SummaryThis PR changes
Confidence Score: 5/5Safe to merge — the change is narrow, well-tested, and strictly improves resilience with no regressions to existing healthy-drive discovery. The implementation change is a small, self-contained catch-block restructure. Every error path is explicitly tested: expected codes are silently skipped, unexpected codes log a warning and skip (new behaviour), and isDirectory() exceptions still propagate as before. No shared state, no async races, no callers affected beyond receiving an empty list instead of a thrown error for the previously-crashing case. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/runtime/windows-drive-listing.ts | Catch block changed to always return null for any statPath error; unexpected errors emit console.warn instead of being rethrown. isDirectory() call intentionally left outside the try-catch so programmer errors still propagate. Logic is clean and correct. |
| src/main/runtime/windows-drive-listing.test.ts | Old it.each systemic-failure test replaced with three precise tests: warn-and-skip for unexpected errno, propagation for isDirectory TypeError, and a mixed healthy/tolerated/unexpected regression test. afterEach restoreAllMocks is correctly added. Coverage of the new behaviour is complete. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[listWindowsDrives called] --> B[Promise.all over A-Z drive letters]
B --> C{statPath succeeds?}
C -- Yes --> D[call stats.isDirectory]
D -- true --> E[include root in list]
D -- false --> F[return null / skip]
D -- throws TypeError --> G[propagate error — Promise.all rejects]
C -- No: error --> H{isExpectedUnavailableDriveError?}
H -- Yes EACCES/ENOENT/ENOTDIR/EPERM --> I[return null silently]
H -- No EIO/EMFILE/etc --> J[console.warn + return null]
E --> K[filter nulls → DriveListing entries]
F --> K
I --> K
J --> K
Reviews (2): Last reviewed commit: "fix(runtime): preserve drive listing pro..." | Re-trigger Greptile
Co-authored-by: Orca <[email protected]>
Co-authored-by: Orca <[email protected]>
Description
Skip every Windows drive whose root cannot be stat'ed so one unreadable or not-ready device cannot reject the complete A:\ through Z:\ enumeration. Expected unavailable-drive errors remain quiet; unexpected stat errors are skipped with a warning that includes the drive root and original error. Only
statPath(root)is tolerated: errors from interpreting a successful stat result still reject. Regression coverage includes EIO alone, a mix of expected, unexpected, and healthy probes, and the programming-error boundary.ELI5
Windows checks every possible drive letter to find the ones that can be opened. One unusual broken or not-ready drive no longer stops the entire check or hides healthy drives. If Orca itself hits a bug while interpreting a successful check, that bug is still reported instead of making the machine appear to have no drives.
Proof of fix
Before narrowing the catch, the new boundary test exercised a
Stats.isDirectory()stub that throwsTypeError('programmer bug').Exact command:
pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/windows-drive-listing.test.tsVerbatim failing output:
After narrowing the catch, the same command passed:
Proof of no regression
Targeted suite for both touched files.
Exact command:
pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/windows-drive-listing.test.tsVerbatim output from the pushed commit:
Exact command:
Verbatim output from the pushed commit:
No user-visible UI change; no screenshot is applicable.
Review remediation
await statPath(root);stats.isDirectory()runs afterward, so programming errors reject instead of being converted to an absent drive.Statsstub withisDirectory()throwingTypeError('programmer bug'); the test assertslistWindowsDrivesrejects with that exact error.Scan provenance
P2 — listWindowsDrives fails closed for the entire 26-drive list on one unexpected errno. Introduced by #7439, “Support Windows drives in the remote host filesystem picker.”
Made with Orca