Skip to content

Bug: walk()/list() fails with ENOENT if directory is deletedΒ #154

Closed

Description

@Knagis

Which packages are affected?

  • @humanfs/box
  • @humanfs/core
  • @humanfs/node
  • @humanfs/deno
  • @humanfs/memory
  • @humanfs/web
  • @humanfs/test
  • @humanfs/types

Environment

Node version: 24.6.0, 22.18.0
Operating System: v24@Windows 11, v22@Ubuntu 24

@humanfs/node: 0.16.6

What did you do?

Running eslint in parallel to other tools that create/delete empty folders made eslint to crash while listing directory contents.

What did you expect to happen?

Deleting an empty directory while linter is running should not crash it.

What actually happened?

Error: ENOENT: no such file or directory, scandir 'D:\js-clients\tsconfig.src.json.lock'
at async Object.readdir (node:internal/fs/promises:958:18)
at async NodeHfsImpl.list (file:///D:/js-clients/node_modules/@humanfs/node/src/node-hfs.js:304:19)
at async NodeHfs.<anonymous> (file:///D:/js-clients/node_modules/@humanfs/core/src/hfs.js:560:21)
at async NodeHfs.<anonymous> (file:///D:/js-clients/node_modules/@humanfs/core/src/hfs.js:604:6)
at async NodeHfs.walk (file:///D:/js-clients/node_modules/@humanfs/core/src/hfs.js:614:3)
at async globSearch (D:\js-clients\node_modules\eslint\lib\eslint\eslint-helpers.js:331:20)
at async Promise.allSettled (index 0)
at async globMultiSearch (D:\js-clients\node_modules\eslint\lib\eslint\eslint-helpers.js:422:18)
at async findFiles (D:\js-clients\node_modules\eslint\lib\eslint\eslint-helpers.js:593:24)
at async ESLint.lintFiles (D:\js-clients\node_modules\eslint\lib\eslint\eslint.js:734:21)

Link to Minimal Reproducible Example

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

previous discussion about ENOENT: eslint/eslint#18955

Activity

  1. changed the title [-]Bug: list() fails with ENOENT if directory is deleted[/-] [+]Bug: walk()/list() fails with ENOENT if directory is deleted[/+] on Aug 25, 2025
  2. Knagis commented on Aug 25, 2025

    @Knagis
    Author

    Issue seems to be that the readdir call is done on the first await of the iterator, not when the function is called, so the existing try/catch has no effect: https://github.com/humanwhocodes/humanfs/blob/main/packages/core/src/hfs.js#L552

    for example, this shows "error on loop":

    function readdir() {
        throw new Error();
    }
    
    async function* list() {
        const entries = await readdir();
    
        for (const entry of entries) {
            yield 123;
        }
    }
    
    let iter;
    try {
        iter = await list();
    } catch (e) {
        console.log("error on call", e);
    }
    
    try {
        for await (const x of iter) {
        }
    } catch (e) {
        console.log("error on loop", e);
    }
    
  3. nzakas commented on Aug 25, 2025

    @nzakas
    Contributor

    Thanks for the report. Can you put together a reproduction case I can look at?

  4. Knagis commented on Aug 25, 2025

    @Knagis
    Author

    the example i posted in the previous comment - it follows the same code structure (async generator) as the walk+list code in this package, and shows that the mitigation implemented in #135 isn't actually working. The test in there does not match the implementation - as the test doesn't implement list as an async generator.

  5. nzakas commented on Aug 28, 2025

    @nzakas
    Contributor

    Right, but that's reproducing your theory of how the bug is working, that's not using the actual code to reproduce the error. That's what I'm asking for.

  6. ken0891992-hub commented on Jul 22, 2026

    @ken0891992-hub

    Duplicate of #164

  7. added a commit that references this issue on Sep 9, 2026
    f829ff5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions