Skip to content

fs.promises API is working but why  #25435

Description

@fxdave
  • 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' })

Activity

  1. cjihrig commented on Jan 10, 2019

    @cjihrig
    Contributor

    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.

  2. fxdave commented on Jan 10, 2019

    @fxdave
    Author

    @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.

  3. richardlau commented on Jan 10, 2019

    @richardlau
    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?

  4. fxdave commented on Jan 11, 2019

    @fxdave
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions