Skip to content

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

@jacobheun

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)),

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateIssues and PRs that are duplicates of other issues or PRs.fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions