From 208db5675ebfcf1decdb106f217a4d4ebf17aa17 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Tue, 28 Feb 2017 16:13:49 +0200 Subject: [PATCH] fs: don't conflate data and callback in appendFile PR-URL: https://github.com/nodejs/node/pull/11607 Reviewed-By: Roman Reiss Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig --- lib/fs.js | 2 +- test/parallel/test-fs-append-file.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index 6273c975c1..25dad8bf2c 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1320,7 +1320,7 @@ fs.writeFileSync = function(path, data, options) { }; fs.appendFile = function(path, data, options, callback) { - callback = maybeCallback(arguments[arguments.length - 1]); + callback = maybeCallback(callback || options); options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' }); // Don't make changes directly on options object diff --git a/test/parallel/test-fs-append-file.js b/test/parallel/test-fs-append-file.js index 025a0ed034..e3e4c273d3 100644 --- a/test/parallel/test-fs-append-file.js +++ b/test/parallel/test-fs-append-file.js @@ -144,6 +144,13 @@ fs.open(filename5, 'a+', function(e, fd) { }); }); +// test that a missing callback emits a warning, even if the last argument is a +// function. +const filename6 = join(common.tmpDir, 'append6.txt'); +const warn = 'Calling an asynchronous function without callback is deprecated.'; +common.expectWarning('DeprecationWarning', warn); +fs.appendFile(filename6, console.log); + process.on('exit', function() { assert.strictEqual(12, ncallbacks);