Skip to content

Commit 208db56

Browse files
committed
fs: don't conflate data and callback in appendFile
PR-URL: #11607 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent df02f39 commit 208db56

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ fs.writeFileSync = function(path, data, options) {
13201320
};
13211321

13221322
fs.appendFile = function(path, data, options, callback) {
1323-
callback = maybeCallback(arguments[arguments.length - 1]);
1323+
callback = maybeCallback(callback || options);
13241324
options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' });
13251325

13261326
// Don't make changes directly on options object

test/parallel/test-fs-append-file.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ fs.open(filename5, 'a+', function(e, fd) {
144144
});
145145
});
146146

147+
// test that a missing callback emits a warning, even if the last argument is a
148+
// function.
149+
const filename6 = join(common.tmpDir, 'append6.txt');
150+
const warn = 'Calling an asynchronous function without callback is deprecated.';
151+
common.expectWarning('DeprecationWarning', warn);
152+
fs.appendFile(filename6, console.log);
153+
147154
process.on('exit', function() {
148155
assert.strictEqual(12, ncallbacks);
149156

0 commit comments

Comments
 (0)