Skip to content

fs.mkdir is inconsistent in the number of arguments passed to the callback , when completed. #43015

Description

@ryan65

Version

16.14

Platform

Window/Linux

Subsystem

No response

What steps will reproduce the bug?

//call mkdir with to create a non existing directory and then when complete call it again with the same directory.
fs.mkdir('c:\\temp\\testdirnonexist',{ recursive: true }, function(){
       console.log('first time', arguments.length); //result 2
       fs.mkdir('c:\\temp\\testdirnonexist',{ recursive: true }, function(){
          console.log('second time', arguments.length); //result 1
       });
});

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

Always return the same number of arguments.
This is important for example when you pass an async waterfall callback to mkdir.

What do you see instead?

if the directory exists only 1 arguments will be returned (error argument which is null)
if directory is created then it returns null, and the path.

Additional information

No response

Activity

  1. daeyeon commented on May 9, 2022

    @daeyeon
    Member

    https://github.com/nodejs/node/blob/master/doc/api/fs.md#fsmkdirpath-options-callback
    According to the document, it seems a correct behavior but there is a missing description for the parameter. I will create a PR to improve it.

    The callback is given a possible exception and, if recursive is true, the first directory path created, (err[, path]). path can still be undefined when recursive is true, if no directory was created.

  2. daeyeon commented on May 9, 2022

    @daeyeon
    Member

    Please let me know if the doc fix isn't enough to resolve your issue.

  3. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on May 9, 2022
  4. ryan65 commented on May 22, 2022

    @ryan65
    Author

    Hi
    Thanks Daeyeon
    I think the documentation now will be clearer, although I personally am still not sure what the most intuitive behavior should
    be, regarding the returned result, since currently its inconsistent. but the documentation at least clarifies this.

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

    fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions