Skip to content

fs methods returning an additional, undefined value in callback #20872

Description

@jacobheun
  • Version: 10.1.0
  • Platform: Darwin 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64
  • Subsystem: fs

In node 10, fs callbacks are returning an extra undefined value. This violates the current api.

The following code

const fs = require('fs');
function callback() {
  console.log(arguments);
}
fs.unlink('/tmp/existing-file.txt', callback)

will output: [Arguments] { '0': null, '1': undefined }

The expected output should be [Arguments] { '0': null }, which it is in node 8.

This creates problems for libraries such as async that expect the signature of fs to only return the error in the callback. fs.unlink is listed above but I have seen the behavior in other methods, such as fs.link.

Sample async code this causes issues with:

const waterfall = require('async/waterfall')
waterfall([
  (callback) => fs.unlink('/tmp/existing-file.txt', callback),
  (callback) => {
    ...
    // Callback is undefined here because "undefined" is being passed into the `unlink` callback along with a null error
    callback()
  }
])

In order to mitigate the issue the above code would have to change

(callback) => fs.unlink('/tmp/existing-file.txt', callback),

to

(callback) => fs.unlink('/tmp/existing-file.txt', err => callback(err)),

Activity

  1. Trott commented on May 21, 2018

    @Trott
    Member

    This appears fixed on the current master branch, so it might be something that is also fixed in the next Node.js release. I'll see if I can figure out what commit changed the behavior back to the expected behavior and then see if it is slated for the next release or not. Uh, unless someone else beats me to it.

  2. added
    duplicateIssues and PRs that are duplicates of other issues or PRs.
    on May 22, 2018
  3. richardlau commented on May 22, 2018

    @richardlau
    Member

    Duplicate of #20335 fixed by #20629.

  4. Trott commented on May 22, 2018

    @Trott
    Member

    The fix for this issue is likely to be included in 10.2.0 but if not that release, then certainly the next release after that.

  5. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on May 22, 2018
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

    duplicateIssues and PRs that are duplicates of other issues or PRs.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