Skip to content

fix: propagate emptyDir directory read errors - #1080

Merged
RyanZim merged 1 commit into
jprichardson:masterfrom
xianjianlf2:fix/empty-dir-read-errors
Sep 17, 2026
Merged

RyanZim merged 1 commit into
jprichardson:masterfrom
xianjianlf2:fix/empty-dir-read-errors

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

emptyDir() and emptyDirSync() currently treat every readdir failure as a missing directory. If the directory exists but cannot be read, recursive mkdir can succeed and the operation reports success without clearing anything.

Only create the directory after ENOENT; propagate other read errors unchanged. Add portable regression tests for EACCES and EIO in 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 reports EACCES.

Validation: npm test passes (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.

@RyanZim RyanZim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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 EACCES and EIO.
File summaries
File Description
lib/empty/index.js Propagates non-ENOENT read errors.
lib/empty/__tests__/empty-dir.test.js Tests Promise and callback error propagation.
lib/empty/__tests__/empty-dir-sync.test.js Tests synchronous error propagation.
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.

@RyanZim
RyanZim merged commit f829cc9 into jprichardson:master Sep 17, 2026
21 checks passed
@RyanZim

RyanZim commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Published in v11.4.1 🎉

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.

3 participants