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

fs.promises API is working but why #25435

Closed
fxdave opened this issue Jan 10, 2019 · 4 comments
Closed

fs.promises API is working but why #25435

fxdave opened this issue Jan 10, 2019 · 4 comments

Comments

@fxdave
Copy link

fxdave commented Jan 10, 2019

  • Version: v10.15.0
  • Platform: Linux dbiro 4.20.0-arch1-1-ARCH deps: update openssl to 1.0.1j #1 SMP PREEMPT Mon Dec 24 03:00:40 UTC 2018 x86_64 GNU/Linux
  • Subsystem: filesystem

Details:

electron-userland/electron-webpack#255

In short:

Here it is the implementation of getOptions:

function getOptions(options, defaultOptions) {
  if (options === null || options === undefined ||
      typeof options === 'function') {
    return defaultOptions;
  }

  if (typeof options === 'string') {
    defaultOptions = util._extend({}, defaultOptions);
    defaultOptions.encoding = options;
    options = defaultOptions;
  } else if (typeof options !== 'object') {
    throw new ERR_INVALID_ARG_TYPE('options', ['string', 'Object'], options);
  }

  if (options.encoding !== 'buffer')
    assertEncoding(options.encoding);
  return options;
}

But this code is working:

const fsp = require('fs')
fsp.readFile(SOME_VALID_URL, { encoding: 'utf8' })
@cjihrig
Copy link
Contributor

cjihrig commented Jan 10, 2019

Are you asking why that code works as expected in Node, but not in electron-webpack? If so, you'd have to take that up with the electron-webpack team.

@fxdave
Copy link
Author

fxdave commented Jan 10, 2019

@cjihrig This code shouldn't work based on the "getOptions" function.

The expected behavior is to throw :

TypeError [ERR_INVALID_OPT_VALUE]: The value "undefined" is invalid for option "flags"
      at stringToFlags (internal/fs/utils.js:253:9)
      at open (internal/fs/promises.js:198:34)
      at Object.readFile (internal/fs/promises.js:466:20)
      ...

Because the object { encoding: 'utf8' } is not containing the flag attribute.
I think it is the getOptions' job, to put the non-optional 'flag' to the given object.

I got the code from the v10.15.0-proposal branch.
But if it is not a node issue, I close it.

@richardlau
Copy link
Member

@cjihrig This code shouldn't work based on the "getOptions" function.

The expected behavior is to throw :

TypeError [ERR_INVALID_OPT_VALUE]: The value "undefined" is invalid for option "flags"
      at stringToFlags (internal/fs/utils.js:253:9)
      at open (internal/fs/promises.js:198:34)
      at Object.readFile (internal/fs/promises.js:466:20)
      ...

Because the object { encoding: 'utf8' } is not containing the flag attribute.
I think it is the getOptions' job, to put the non-optional 'flag' to the given object.

I got the code from the v10.15.0-proposal branch.
But if it is not a node issue, I close it.

Wasn't this fixed by #20268?

@fxdave
Copy link
Author

fxdave commented Jan 11, 2019

@richardlau You are right, then I got wrong source from debugger. Closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants