Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: filehandle.truncate(len) broken using yarn node #4372

Closed
1 task
tellnes opened this issue Apr 18, 2022 · 2 comments · Fixed by #3889
Closed
1 task

[Bug?]: filehandle.truncate(len) broken using yarn node #4372

tellnes opened this issue Apr 18, 2022 · 2 comments · Fixed by #3889
Assignees
Labels
bug Something isn't working reproducible This issue can be successfully reproduced

Comments

@tellnes
Copy link
Contributor

tellnes commented Apr 18, 2022

Self-service

  • I'd be willing to implement a fix

Describe the bug

The following code works if it is run as node bug.mjs, but fails if it is run as yarn node bug.mjs

import { open } from 'fs/promises'
const handle = await open('test.txt', 'w')
await handle.truncate(0)
await handle.close()

Here is the output when running with yarn node:

node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (20)
    at new NodeError (node:internal/errors:372:5)
    at validateString (node:internal/validators:120:11)
    at Object.isAbsolute (node:path:1157:5)
    at VirtualFS.mapToBase (/Users/christian/dev/github/yarnpkg/berry/.pnp.cjs:48282:24)
    at VirtualFS.truncatePromise (/Users/christian/dev/github/yarnpkg/berry/.pnp.cjs:48182:45)
    at PosixFS.truncatePromise (/Users/christian/dev/github/yarnpkg/berry/.pnp.cjs:48182:24)
    at URLFS.truncatePromise (/Users/christian/dev/github/yarnpkg/berry/.pnp.cjs:48182:24)
    at FileHandle.truncate (/Users/christian/dev/github/yarnpkg/berry/.pnp.cjs:49331:27)
    at file:///Users/christian/dev/github/yarnpkg/berry/bug.mjs:3:14 {
  code: 'ERR_INVALID_ARG_TYPE'
}

To reproduce

const { open } = require('fs/promises')

await expect(async function () {
  const handle = await open('test.txt', 'w')
  await handle.truncate(0)
  await handle.close()
}()).resolves.toBeUndefined()

Environment

Binaries:
    Node: 17.9.0 - /private/var/folders/2n/50s_kk9s64jcd16qkxnf9b_40000gn/T/xfs-107d9a4f/node
    Yarn: 4.0.0-rc.2.dev - /private/var/folders/2n/50s_kk9s64jcd16qkxnf9b_40000gn/T/xfs-107d9a4f/yarn
    npm: 8.5.5 - /usr/local/bin/npm

Additional context

No response

@tellnes tellnes added the bug Something isn't working label Apr 18, 2022
@yarnbot

This comment has been minimized.

@yarnbot yarnbot added the reproducible This issue can be successfully reproduced label Apr 18, 2022
@tellnes tellnes changed the title [Bug?]: filehandle.truncate(len) broken using Yarn [Bug?]: filehandle.truncate(len) broken using yarn node Apr 18, 2022
@yarnbot
Copy link
Collaborator

yarnbot commented Apr 18, 2022

This issue reproduces on master:

Error: expect(received).resolves.toBeUndefined()

Received promise rejected instead of resolved
Rejected to value: [TypeError: The "path" argument must be of type string. Received type number (54)]
    at expect (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-44ff9ab1e7.zip/node_modules/expect/build/index.js:138:15)
    at module.exports (evalmachine.<anonymous>:4:7)
    at /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:19
    at executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:22)
    at executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:18)
    at ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:76)
    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible This issue can be successfully reproduced
Projects
None yet
3 participants