Skip to content

fix(runtime): skip unreadable Windows drives - #11421

Merged
nwparker merged 2 commits into
mainfrom
fix/windows-drive-listing-skip-unreadable-drives
Jul 30, 2026
Merged

nwparker merged 2 commits into
mainfrom
fix/windows-drive-listing-skip-unreadable-drives

Conversation

@nwparker

@nwparker nwparker commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

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 throws TypeError('programmer bug').

Exact command:

pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/windows-drive-listing.test.ts

Verbatim failing output:

 RUN  v4.1.5 /Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3

stderr | src/main/runtime/windows-drive-listing.test.ts > listWindowsDrives > surfaces programming errors from isDirectory
[windows-drive-listing] Failed to stat drive {
  root: 'D:\\',
  error: TypeError: programmer bug
      at /Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/src/main/runtime/windows-drive-listing.test.ts:79:19
      at file:///Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/chunk-artifact.js:302:11
      at file:///Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/chunk-artifact.js:1903:26
      at file:///Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/chunk-artifact.js:2326:20
      at new Promise (<anonymous>)
      at runWithCancel (file:///Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/chunk-artifact.js:2323:10)
      at file:///Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/chunk-artifact.js:2305:20
      at new Promise (<anonymous>)
      at runWithTimeout (file:///Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/chunk-artifact.js:2272:10)
      at file:///Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3/node_modules/.pnpm/@[email protected]/node_modules/@vitest/runner/dist/chunk-artifact.js:2955:64
}

 ❯ src/main/runtime/windows-drive-listing.test.ts (7 tests | 1 failed) 6ms
     × surfaces programming errors from isDirectory 3ms

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/main/runtime/windows-drive-listing.test.ts > listWindowsDrives > surfaces programming errors from isDirectory
AssertionError: promise resolved "{ resolvedPath: '/', …(2) }" instead of rejecting

- Expected
+ Received

- Error {
-   "message": "rejected promise",
+ {
+   "entries": [],
+   "pathFlavor": "win32",
+   "resolvedPath": "/",
  }

 ❯ src/main/runtime/windows-drive-listing.test.ts:91:46
     89|     }
     90|
     91|     await expect(listWindowsDrives(statPath)).rejects.toBe(error)
       |                                              ^
     92|   })
     93|

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


 Test Files  1 failed (1)
      Tests  1 failed | 6 passed (7)
   Start at  19:57:00
   Duration  103ms (transform 17ms, setup 0ms, import 22ms, tests 6ms, environment 0ms)

After narrowing the catch, the same command passed:

 RUN  v4.1.5 /Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3


 Test Files  1 passed (1)
      Tests  7 passed (7)
   Start at  19:57:30
   Duration  85ms (transform 15ms, setup 0ms, import 21ms, tests 3ms, environment 0ms)

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.ts

Verbatim output from the pushed commit:

 RUN  v4.1.5 /Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3


 Test Files  1 passed (1)
      Tests  7 passed (7)
   Start at  19:57:30
   Duration  85ms (transform 15ms, setup 0ms, import 21ms, tests 3ms, environment 0ms)

Exact command:

pnpm run typecheck

Verbatim output from the pushed commit:

> [email protected] typecheck /Users/nwparker/projects/orca/.claude/worktrees/wf_228b4bf9-149-3
> tsc --noEmit -p config/tsconfig.node.json && tsc --noEmit -p config/tsconfig.tc.cli.json && tsc --noEmit -p config/tsconfig.tc.web.json

No user-visible UI change; no screenshot is applicable.

Review remediation

  1. Catch is too broad: Confirmed. The catch now wraps only await statPath(root); stats.isDirectory() runs afterward, so programming errors reject instead of being converted to an absent drive.
  2. Missing boundary test: Added a regression test whose successful stat returns a Stats stub with isDirectory() throwing TypeError('programmer bug'); the test asserts listWindowsDrives rejects 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

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

listWindowsDrives now skips drives when root stat fails, logs warnings for unexpected errors, and continues returning healthy drives. Expected unavailable-drive errors remain silently excluded. Tests now restore Vitest mocks and cover warning payloads, mixed drive outcomes, and propagation of isDirectory errors.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning Missing the required template sections for Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite the PR description to match the repository template and include the missing sections, checklist items, security audit, AI review, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed Clearly summarizes the main change: unreadable Windows drives are skipped during enumeration.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment on lines +58 to +76
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
})
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 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-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR changes listWindowsDrives so that a single unreadable drive can no longer abort the entire A–Z enumeration. Previously, only a hard-coded set of "expected" error codes (EACCES, ENOENT, ENOTDIR, EPERM) were swallowed silently; any other code (e.g. EIO) was rethrown and short-circuited Promise.all, hiding all healthy drives.

  • Implementation: The try-catch now catches every statPath rejection; expected codes are silently skipped and unexpected codes emit a console.warn before returning null for that drive slot. Errors thrown by isDirectory() are intentionally left outside the try-catch so programmer bugs still propagate.
  • Tests: The old it.each(['EIO','EMFILE']) "surfaces systemic failures" test is replaced by three targeted tests — one for the new warn-and-skip path (EIO), one for the isDirectory propagation path, and one mixed-drive regression test combining healthy, tolerated, and unexpected failures.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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
Loading

Reviews (2): Last reviewed commit: "fix(runtime): preserve drive listing pro..." | Re-trigger Greptile

@nwparker
nwparker merged commit 191fdf2 into main Jul 30, 2026
41 checks passed
@nwparker
nwparker deleted the fix/windows-drive-listing-skip-unreadable-drives branch July 30, 2026 07:23
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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