yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.35k stars 1.1k forks source link

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

Open alvinleung1996 opened 1 year ago

alvinleung1996 commented 1 year ago

Self-service

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

yarnbot commented 1 year ago

This issue reproduces on master:

Error: expect(received).toBe(expected) // Object.is equality

Expected: "rejected: ENOENT"
Received: "resolved"
    at module.exports (evalmachine.<anonymous>:17:16)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)