Skip to content

fix: Ensure walk() doesn't error out on directory ENOENT - #135

Merged
nzakas merged 1 commit into
mainfrom
enonent-walk
Oct 18, 2024
Merged

nzakas merged 1 commit into
mainfrom
enonent-walk

Conversation

@nzakas

@nzakas nzakas commented Oct 18, 2024

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request?

Ensures that walk() doesn't error out on ENOENT errors. Due to the asynchronous nature of listing directory entries, it's possible that a directory may have been deleted before list() is called on it.

Other packages that do this:

Refs eslint/eslint#18955

What changes did you make? (Give an overview)

This pull request includes changes to handle directory listing errors more gracefully in the Hfs class and adds corresponding tests to ensure the new behavior is correct. The most important changes include modifying the walk method to handle ENOENT errors, updating the test suite to include a test for this new behavior, and importing necessary error classes.

Error handling improvements:

  • packages/core/src/hfs.js: Modified the walk method to catch ENOENT errors and return an empty array instead of throwing an error.

Test suite updates:

@nzakas
nzakas merged commit 05873f8 into main Oct 18, 2024
@nzakas
nzakas deleted the enonent-walk branch October 18, 2024 21:17
@github-actions github-actions Bot mentioned this pull request Oct 18, 2024
nzakas added a commit that referenced this pull request Sep 9, 2026
`NodeHfsImpl#list()` and `DenoHfsImpl#list()` are async generators, so
the directory isn't actually read until the iterator is first advanced.
The ENOENT handling added in #135 only wrapped the call to `list()`,
so an ENOENT thrown during iteration (e.g. a directory deleted between
being discovered and being listed) escaped `walk()`.

`walk()` now drives the `list()` iterator manually, catching ENOENT from
`next()` and stopping the walk of that directory, while still rethrowing
other errors and closing the iterator on early exit.

Fixes #154

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019DHXVwqQ4iawKrV2DxPVKV
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