fix: Ensure walk() doesn't error out on directory ENOENT #135
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 beforelist()
is called on it.Other packages that do this:
glob
- https://github.com/isaacs/node-glob/blob/main/src/processor.ts#L138fast-glob
- https://github.com/mrmlnc/fast-glob/blob/master/src/providers/filters/error.ts#L18Refs 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 thewalk
method to handleENOENT
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 thewalk
method to catchENOENT
errors and return an empty array instead of throwing an error.Test suite updates:
packages/core/tests/hfs.test.js
: Added a new test case to verify that thewalk
method silently skips directories whenlist()
throws anENOENT
error.packages/core/tests/hfs.test.js
: ImportedNotFoundError
fromerrors.js
to use in the new test case.