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] p.match is not a function while using filehandle of fs.promises. #1889

Closed
LvChengbin opened this issue Sep 28, 2020 · 1 comment · Fixed by #3889
Closed

[Bug] p.match is not a function while using filehandle of fs.promises. #1889

LvChengbin opened this issue Sep 28, 2020 · 1 comment · Fixed by #3889
Labels
bug Something isn't working reproducible This issue can be successfully reproduced

Comments

@LvChengbin
Copy link

% yarn -v
2.2.2
% yarn node
Welcome to Node.js v14.7.0.
Type ".help" for more information.
> const fs = require( 'fs' ).promises;
undefined
> fs.open( './index.js' ).then( fd => fd.stat() ).then( stat => console.log( stat ) );
Promise { <pending> }
> (node:76736) UnhandledPromiseRejectionWarning: TypeError: p.match is not a function
    at Function.resolveVirtual (/x/.pnp.js:5170:21)
    at VirtualFS.mapToBase (/x/.pnp.js:5207:22)
    at VirtualFS.statPromise (/x/.pnp.js:4948:41)
    at PosixFS.statPromise (/x/.pnp.js:4948:24)
    at FileHandle.stat (/x/.pnp.js:8077:27)
    at repl:1:40
 % node
Welcome to Node.js v14.7.0.
Type ".help" for more information.
> const fs = require( 'fs' ).promises;
undefined
> fs.open( './index.js' ).then( fd => fd.stat() ).then( stat => console.log( stat ) );
Promise { <pending> }
> Stats {
  dev: 16777220,
  mode: 33188,
  nlink: 1,
  uid: 501,
  gid: 80,
  rdev: 0,
  blksize: 4096,
  ino: 83137944,
  size: 0,
  blocks: 0,
  atimeMs: 1601261525682.7114,
  mtimeMs: 1601261525682.7114,
  ctimeMs: 1601261525682.7114,
  birthtimeMs: 1601261525682.7114,
  atime: 2020-09-28T02:52:05.683Z,
  mtime: 2020-09-28T02:52:05.683Z,
  ctime: 2020-09-28T02:52:05.683Z,
  birthtime: 2020-09-28T02:52:05.683Z
}
@CoalZombik
Copy link

I have same problem (yarn v2.4.2) and after updating to version from sources, I get more descriptive error.

Test source code:

const fs_promises = require('fs').promises;
fs_promises.open(__filename, 'r').then((fh) => {
	console.log(fh);
	return fh.stat();
}).then(console.log);

Console output:

FileHandle { fd: 17 }
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (17)
    at new NodeError (node:internal/errors:363:5)
    at validateString (node:internal/validators:119:11)
    at Object.isAbsolute (node:path:1157:5)
    at VirtualFS.mapToBase (.pnp.cjs:14620:24)
    at VirtualFS.statPromise (.pnp.cjs:14345:41)
    at PosixFS.statPromise (.pnp.cjs:14345:24)
    at URLFS.statPromise (.pnp.cjs:14345:24)
    at FileHandle.stat (.pnp.cjs:17754:27)
    at test.js:4:12 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Yarn version: 3.0.0-rc.6.git.20210622.hash-4f9a9092
Node version: v16.4.0

I think that the source of this problem is calling a function (in this specific scenario statPromise) from URLFS (respectively from ProxiedFS<NativePath, NativePath>) in patchFs.ts:230

return fakeImpl.call(fakeFs, this.fd, ...args);

First argument is passing a file description (i.e. number), but its expected a NativePath (i.e. string).

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
Development

Successfully merging a pull request may close this issue.

3 participants