Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for fs.appendFile failure when a callback isn't passed and an is error returned #3853

Closed
wants to merge 1 commit into from

4 participants

@crazyrobot

Documentation for 'fs.appendFile' marks the 'callback' argument as optional, but the code would fail if not passed a callback function and an error has occurred.

The code defaulted to 'null' which was later called as a function in the case of an error.

Fixed to use (the already defined) 'makeCallback' function.

@bnoordhuis

LGTM if it works as advertised. However:

  1. Can you add a regression test or two?
  2. Can you rework the commit message as described here?
  3. Last but not least, can you sign the CLA?

Thanks!

@crazyrobot

Sorry about that. My fault for not searching the notes about contributing.
Will fix the commit message and sign the CLA now and take care of the test tomorrow.

@crazyrobot crazyrobot fs: fix appendFile() error using null as function
Code defaulted to 'null' if a callback wasn't provided which would later be called as a function in the case of an error.
Changed to use 'makeCallback' like on 'fs.symlink'.
9c38d69
@Nodejs-Jenkins

Can one of the admins verify this patch?

@tjfontaine
Owner

This is fixed in current releases.

@tjfontaine tjfontaine closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 12, 2012
  1. @crazyrobot

    fs: fix appendFile() error using null as function

    crazyrobot authored
    Code defaulted to 'null' if a callback wasn't provided which would later be called as a function in the case of an error.
    Changed to use 'makeCallback' like on 'fs.symlink'.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 2 deletions.
  1. +1 −2  lib/fs.js
View
3  lib/fs.js
@@ -818,8 +818,7 @@ fs.writeFileSync = function(path, data, encoding) {
fs.appendFile = function(path, data, encoding_, callback) {
var encoding = (typeof(encoding_) == 'string' ? encoding_ : 'utf8');
- var callback_ = arguments[arguments.length - 1];
- callback = (typeof(callback_) == 'function' ? callback_ : null);
+ var callback = makeCallback(arguments[arguments.length - 1]);
fs.open(path, 'a', 438 /*=0666*/, function(err, fd) {
if (err) return callback(err);
Something went wrong with that request. Please try again.