From 4cb5f3daa350421e4eb4622dc818633d3a0659b3 Mon Sep 17 00:00:00 2001 From: "Sakthipriyan Vairamani (thefourtheye)" Date: Fri, 21 Apr 2017 10:16:15 +0530 Subject: [PATCH] fs: throw on invalid callbacks for async functions If an asynchronous function is passed no callback function, there is no way to return the result. This patch throws an error if the callback passed is not valid or none passed at all. PR-URL: https://github.com/nodejs/node/pull/12562 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- doc/api/deprecations.md | 5 +- doc/api/fs.md | 180 +++++++++++++++++---- lib/fs.js | 60 ++----- test/fixtures/test-fs-readfile-error.js | 2 +- test/parallel/test-fs-access.js | 4 +- test/parallel/test-fs-link.js | 4 +- test/parallel/test-fs-make-callback.js | 8 +- test/parallel/test-fs-makeStatsCallback.js | 8 +- test/parallel/test-fs-mkdtemp.js | 5 - test/parallel/test-fs-readfile-error.js | 2 +- test/parallel/test-fs-write-no-fd.js | 6 +- 11 files changed, 180 insertions(+), 104 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 96e9f927d34..82c115d02f1 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -150,9 +150,10 @@ explicitly via error event handlers set on the domain instead. ### DEP0013: fs async function without callback -Type: Runtime +Type: End-of-Life -Calling an asynchronous function without a callback is deprecated. +Calling an asynchronous function without a callback will throw a `TypeError` +v8.0.0 onwards. Refer: [PR 12562](https://github.com/nodejs/node/pull/12562) ### DEP0014: fs.read legacy String interface diff --git a/doc/api/fs.md b/doc/api/fs.md index 16311dead44..e867e994349 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -551,10 +551,14 @@ checks fail, and does nothing otherwise. * `path` {string|Buffer|URL} @@ -655,6 +663,10 @@ Synchronous chmod(2). Returns `undefined`. * `path` {string|Buffer|URL} @@ -693,10 +705,14 @@ Synchronous chown(2). Returns `undefined`. * `fd` {integer} @@ -987,10 +1003,14 @@ a callback.) * `fd` {integer} @@ -1014,10 +1034,14 @@ Synchronous fchmod(2). Returns `undefined`. * `fd` {integer} @@ -1043,10 +1067,14 @@ Synchronous fchown(2). Returns `undefined`. * `fd` {integer} @@ -1068,10 +1096,14 @@ Synchronous fdatasync(2). Returns `undefined`. * `fd` {integer} @@ -1094,10 +1126,14 @@ Synchronous fstat(2). Returns an instance of [`fs.Stats`][]. * `fd` {integer} @@ -1119,10 +1155,14 @@ Synchronous fsync(2). Returns `undefined`. * `fd` {integer} @@ -1187,10 +1227,14 @@ Synchronous ftruncate(2). Returns `undefined`. * `path` {string|Buffer} @@ -1254,10 +1302,14 @@ Synchronous lchmod(2). Returns `undefined`. * `path` {string|Buffer} @@ -1283,6 +1335,10 @@ Synchronous lchown(2). Returns `undefined`. * `existingPath` {string|Buffer|URL} @@ -1321,6 +1377,10 @@ Synchronous link(2). Returns `undefined`. * `path` {string|Buffer|URL} @@ -1357,6 +1417,10 @@ Synchronous lstat(2). Returns an instance of [`fs.Stats`][]. * `path` {string|Buffer|URL} @@ -1393,10 +1457,14 @@ Synchronous mkdir(2). Returns `undefined`. * `path` {string|Buffer|URL} @@ -1840,6 +1920,10 @@ Synchronous version of [`fs.read()`][]. Returns the number of `bytesRead`. * `oldPath` {string|Buffer|URL} @@ -1944,6 +2032,10 @@ Synchronous rename(2). Returns `undefined`. * `path` {string|Buffer|URL} @@ -1978,6 +2070,10 @@ Synchronous rmdir(2). Returns `undefined`. * `path` {string|Buffer|URL} @@ -2070,10 +2166,14 @@ Synchronous symlink(2). Returns `undefined`. * `path` {string|Buffer} @@ -2099,6 +2199,10 @@ passed as the first argument. In this case, `fs.ftruncateSync()` is called. * `path` {string|Buffer|URL} @@ -2152,6 +2256,10 @@ when possible. * `fd` {integer} @@ -2414,13 +2526,17 @@ the end of the file. * `fd` {integer} @@ -2458,13 +2574,17 @@ the end of the file.