Skip to content

[Bug?]: fs.promises.open doesn't throw ENOENT when path doesn't exist #4920

Open
@alvinleung1996

Description

@alvinleung1996

Self-service

  • I'd be willing to implement a fix

Describe the bug

fs.promises.open resolves with a FileHandle object when given an non-existing file path.

The correct behavior should be throwing an error with code ENOENT.

To reproduce

await packageJsonAndInstall({
  dependencies: {
    'tslib': '*',
  },
})

const realPath = await node(`require.resolve('tslib/package.json')`)
const fakePath = `${realPath}.fake`

const result = await node(`
  require('fs/promises')
    .open(${JSON.stringify(fakePath)})
    .then(() => 'resolved')
    .catch((err) => \`rejected: \${err.code}\`)
`)
expect(result).toBe('rejected: ENOENT')

Environment

System:
  OS: Linux 5.10 Alpine Linux
  CPU: (8) x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
Binaries:
  Node: 16.17.1 - /tmp/xfs-28478f54/node
  Yarn: 3.2.3 - /tmp/xfs-28478f54/yarn
  npm: 8.15.0 - /usr/local/bin/npm

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreproducibleThis issue can be successfully reproduced

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions