Repository navigation
fix: propagate emptyDir directory read errors - #1080
Conversation
RyanZim
left a comment
There was a problem hiding this comment.
Good catch, and thanks for submitting the PR!
One thing this will change is that if the specified path is a file, it will now error with ENOTDIR instead of EEXIST. This does make more sense, but I'm unsure if anyone is depending on this specific error code (i.e. should this be considered a breaking change?).
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix correctly preserves missing-directory behavior and comprehensively tests affected interfaces.
Pull request overview
Fixes emptyDir so only missing directories are created, while other read failures propagate unchanged.
Changes:
- Restricts recovery to
ENOENT. - Adds Promise, callback, and synchronous regression tests for
EACCESandEIO.
File summaries
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

emptyDir()andemptyDirSync()currently treat everyreaddirfailure as a missing directory. If the directory exists but cannot be read, recursivemkdircan succeed and the operation reports success without clearing anything.Only create the directory after
ENOENT; propagate other read errors unchanged. Add portable regression tests forEACCESandEIOin the Promise, callback, and synchronous interfaces. All five new tests fail before the fix; existing missing-directory tests still pass.Also reproduced on a real macOS directory with mode
000: the original implementation returns success with its file untouched, while the patch reportsEACCES.Validation:
npm testpasses (Standard lint, 737 unit tests with 8 existing skips, and ESM tests). The changed empty-directory module has 100% coverage.AI assistance: implemented and tested with OpenAI Codex.