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 <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
e429f9a42a
commit
4cb5f3daa3
@ -150,9 +150,10 @@ explicitly via error event handlers set on the domain instead.
|
|||||||
<a id="DEP0013"></a>
|
<a id="DEP0013"></a>
|
||||||
### DEP0013: fs async function without callback
|
### 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)
|
||||||
|
|
||||||
<a id="DEP0014"></a>
|
<a id="DEP0014"></a>
|
||||||
### DEP0014: fs.read legacy String interface
|
### DEP0014: fs.read legacy String interface
|
||||||
|
180
doc/api/fs.md
180
doc/api/fs.md
@ -551,10 +551,14 @@ checks fail, and does nothing otherwise.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.6.7
|
added: v0.6.7
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7831
|
pr-url: https://github.com/nodejs/node/pull/7831
|
||||||
description: The passed `options` object will never be modified.
|
description: The passed `options` object will never be modified.
|
||||||
@ -619,6 +623,10 @@ The synchronous version of [`fs.appendFile()`][]. Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.30
|
added: v0.1.30
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -626,7 +634,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -655,6 +663,10 @@ Synchronous chmod(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.97
|
added: v0.1.97
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -662,7 +674,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -693,10 +705,14 @@ Synchronous chown(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.0.2
|
added: v0.0.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -987,10 +1003,14 @@ a callback.)
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.4.7
|
added: v0.4.7
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -1014,10 +1034,14 @@ Synchronous fchmod(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.4.7
|
added: v0.4.7
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -1043,10 +1067,14 @@ Synchronous fchown(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.96
|
added: v0.1.96
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -1068,10 +1096,14 @@ Synchronous fdatasync(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.95
|
added: v0.1.95
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -1094,10 +1126,14 @@ Synchronous fstat(2). Returns an instance of [`fs.Stats`][].
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.96
|
added: v0.1.96
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -1119,10 +1155,14 @@ Synchronous fsync(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.8.6
|
added: v0.8.6
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -1187,10 +1227,14 @@ Synchronous ftruncate(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.4.2
|
added: v0.4.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v4.1.0
|
- version: v4.1.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/2387
|
pr-url: https://github.com/nodejs/node/pull/2387
|
||||||
description: Numeric strings, `NaN` and `Infinity` are now allowed
|
description: Numeric strings, `NaN` and `Infinity` are now allowed
|
||||||
@ -1225,10 +1269,14 @@ Synchronous version of [`fs.futimes()`][]. Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
deprecated: v0.4.7
|
deprecated: v0.4.7
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer}
|
* `path` {string|Buffer}
|
||||||
@ -1254,10 +1302,14 @@ Synchronous lchmod(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
deprecated: v0.4.7
|
deprecated: v0.4.7
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer}
|
* `path` {string|Buffer}
|
||||||
@ -1283,6 +1335,10 @@ Synchronous lchown(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.31
|
added: v0.1.31
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `existingPath` and `newPath` parameters can be WHATWG
|
description: The `existingPath` and `newPath` parameters can be WHATWG
|
||||||
@ -1291,7 +1347,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `existingPath` {string|Buffer|URL}
|
* `existingPath` {string|Buffer|URL}
|
||||||
@ -1321,6 +1377,10 @@ Synchronous link(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.30
|
added: v0.1.30
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -1328,7 +1388,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -1357,6 +1417,10 @@ Synchronous lstat(2). Returns an instance of [`fs.Stats`][].
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.8
|
added: v0.1.8
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -1364,7 +1428,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -1393,10 +1457,14 @@ Synchronous mkdir(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v5.10.0
|
added: v5.10.0
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v6.2.1
|
- version: v6.2.1
|
||||||
pr-url: https://github.com/nodejs/node/pull/6828
|
pr-url: https://github.com/nodejs/node/pull/6828
|
||||||
description: The `callback` parameter is optional now.
|
description: The `callback` parameter is optional now.
|
||||||
@ -1619,6 +1687,10 @@ a Promise for an object with `bytesRead` and `buffer` properties.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.8
|
added: v0.1.8
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -1626,7 +1698,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v6.0.0
|
- version: v6.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/5616
|
pr-url: https://github.com/nodejs/node/pull/5616
|
||||||
description: The `options` parameter was added.
|
description: The `options` parameter was added.
|
||||||
@ -1672,6 +1744,10 @@ the filenames returned will be passed as `Buffer` objects.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.29
|
added: v0.1.29
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -1679,7 +1755,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v5.1.0
|
- version: v5.1.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/3740
|
pr-url: https://github.com/nodejs/node/pull/3740
|
||||||
description: The `callback` will always be called with `null` as the `error`
|
description: The `callback` will always be called with `null` as the `error`
|
||||||
@ -1775,6 +1851,10 @@ fs.readFileSync('<directory>'); // => null, <data>
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.31
|
added: v0.1.31
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -1782,7 +1862,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -1840,6 +1920,10 @@ Synchronous version of [`fs.read()`][]. Returns the number of `bytesRead`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.31
|
added: v0.1.31
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using
|
description: The `path` parameter can be a WHATWG `URL` object using
|
||||||
@ -1847,7 +1931,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v6.4.0
|
- version: v6.4.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7899
|
pr-url: https://github.com/nodejs/node/pull/7899
|
||||||
description: Calling `realpath` now works again for various edge cases
|
description: Calling `realpath` now works again for various edge cases
|
||||||
@ -1906,6 +1990,10 @@ will be passed as a `Buffer` object.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.0.2
|
added: v0.0.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `oldPath` and `newPath` parameters can be WHATWG `URL`
|
description: The `oldPath` and `newPath` parameters can be WHATWG `URL`
|
||||||
@ -1914,7 +2002,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `oldPath` {string|Buffer|URL}
|
* `oldPath` {string|Buffer|URL}
|
||||||
@ -1944,6 +2032,10 @@ Synchronous rename(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.0.2
|
added: v0.0.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameters can be a WHATWG `URL` object using
|
description: The `path` parameters can be a WHATWG `URL` object using
|
||||||
@ -1951,7 +2043,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -1978,6 +2070,10 @@ Synchronous rmdir(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.0.2
|
added: v0.0.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -1985,7 +2081,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -2070,10 +2166,14 @@ Synchronous symlink(2). Returns `undefined`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.8.6
|
added: v0.8.6
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer}
|
* `path` {string|Buffer}
|
||||||
@ -2099,6 +2199,10 @@ passed as the first argument. In this case, `fs.ftruncateSync()` is called.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.0.2
|
added: v0.0.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -2106,7 +2210,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `path` {string|Buffer|URL}
|
* `path` {string|Buffer|URL}
|
||||||
@ -2152,6 +2256,10 @@ when possible.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.4.2
|
added: v0.4.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.6.0
|
- version: v7.6.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10739
|
pr-url: https://github.com/nodejs/node/pull/10739
|
||||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||||
@ -2159,7 +2267,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v4.1.0
|
- version: v4.1.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/2387
|
pr-url: https://github.com/nodejs/node/pull/2387
|
||||||
description: Numeric strings, `NaN` and `Infinity` are now allowed
|
description: Numeric strings, `NaN` and `Infinity` are now allowed
|
||||||
@ -2368,6 +2476,10 @@ to compare `curr.mtime` and `prev.mtime`.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.0.2
|
added: v0.0.2
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.4.0
|
- version: v7.4.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10382
|
pr-url: https://github.com/nodejs/node/pull/10382
|
||||||
description: The `buffer` parameter can now be a `Uint8Array`.
|
description: The `buffer` parameter can now be a `Uint8Array`.
|
||||||
@ -2377,7 +2489,7 @@ changes:
|
|||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -2414,13 +2526,17 @@ the end of the file.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.11.5
|
added: v0.11.5
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.2.0
|
- version: v7.2.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7856
|
pr-url: https://github.com/nodejs/node/pull/7856
|
||||||
description: The `position` parameter is optional now.
|
description: The `position` parameter is optional now.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
* `fd` {integer}
|
* `fd` {integer}
|
||||||
@ -2458,13 +2574,17 @@ the end of the file.
|
|||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v0.1.29
|
added: v0.1.29
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/12562
|
||||||
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
|
it will throw a `TypeError` at runtime.
|
||||||
- version: v7.4.0
|
- version: v7.4.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/10382
|
pr-url: https://github.com/nodejs/node/pull/10382
|
||||||
description: The `data` parameter can now be a `Uint8Array`.
|
description: The `data` parameter can now be a `Uint8Array`.
|
||||||
- version: v7.0.0
|
- version: v7.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/7897
|
pr-url: https://github.com/nodejs/node/pull/7897
|
||||||
description: The `callback` parameter is no longer optional. Not passing
|
description: The `callback` parameter is no longer optional. Not passing
|
||||||
it will emit a deprecation warning.
|
it will emit a deprecation warning with id DEP0013.
|
||||||
- version: v5.0.0
|
- version: v5.0.0
|
||||||
pr-url: https://github.com/nodejs/node/pull/3163
|
pr-url: https://github.com/nodejs/node/pull/3163
|
||||||
description: The `file` parameter can be a file descriptor now.
|
description: The `file` parameter can be a file descriptor now.
|
||||||
|
60
lib/fs.js
60
lib/fs.js
@ -58,7 +58,6 @@ const kMaxLength = require('buffer').kMaxLength;
|
|||||||
|
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
|
|
||||||
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
|
|
||||||
const errnoException = util._errnoException;
|
const errnoException = util._errnoException;
|
||||||
|
|
||||||
function getOptions(options, defaultOptions) {
|
function getOptions(options, defaultOptions) {
|
||||||
@ -88,48 +87,26 @@ function copyObject(source) {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
function rethrow() {
|
var internalErrors;
|
||||||
// TODO(thefourtheye) Throw error instead of warning in major version > 7
|
function lazyErrors() {
|
||||||
process.emitWarning(
|
if (!internalErrors)
|
||||||
'Calling an asynchronous function without callback is deprecated.',
|
internalErrors = require('internal/errors');
|
||||||
'DeprecationWarning', 'DEP0013', rethrow
|
return internalErrors;
|
||||||
);
|
|
||||||
|
|
||||||
// Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
|
|
||||||
// is fairly slow to generate.
|
|
||||||
if (DEBUG) {
|
|
||||||
var backtrace = new Error();
|
|
||||||
return function(err) {
|
|
||||||
if (err) {
|
|
||||||
backtrace.stack = err.name + ': ' + err.message +
|
|
||||||
backtrace.stack.substr(backtrace.name.length);
|
|
||||||
throw backtrace;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return function(err) {
|
|
||||||
if (err) {
|
|
||||||
throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeCallback(cb) {
|
function maybeCallback(cb) {
|
||||||
return typeof cb === 'function' ? cb : rethrow();
|
if (typeof cb === 'function')
|
||||||
|
return cb;
|
||||||
|
else
|
||||||
|
throw new (lazyErrors().TypeError)('ERR_INVALID_CALLBACK');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that callbacks run in the global context. Only use this function
|
// Ensure that callbacks run in the global context. Only use this function
|
||||||
// for callbacks that are passed to the binding layer, callbacks that are
|
// for callbacks that are passed to the binding layer, callbacks that are
|
||||||
// invoked from JS already run in the proper scope.
|
// invoked from JS already run in the proper scope.
|
||||||
function makeCallback(cb) {
|
function makeCallback(cb) {
|
||||||
if (cb === undefined) {
|
if (typeof cb !== 'function')
|
||||||
return rethrow();
|
throw new (lazyErrors().TypeError)('ERR_INVALID_CALLBACK');
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof cb !== 'function') {
|
|
||||||
throw new TypeError('"callback" argument must be a function');
|
|
||||||
}
|
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
return cb.apply(null, arguments);
|
return cb.apply(null, arguments);
|
||||||
@ -140,13 +117,8 @@ function makeCallback(cb) {
|
|||||||
// an optimization, since the data passed back to the callback needs to be
|
// an optimization, since the data passed back to the callback needs to be
|
||||||
// transformed anyway.
|
// transformed anyway.
|
||||||
function makeStatsCallback(cb) {
|
function makeStatsCallback(cb) {
|
||||||
if (cb === undefined) {
|
if (typeof cb !== 'function')
|
||||||
return rethrow();
|
throw new (lazyErrors().TypeError)('ERR_INVALID_CALLBACK');
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof cb !== 'function') {
|
|
||||||
throw new TypeError('"callback" argument must be a function');
|
|
||||||
}
|
|
||||||
|
|
||||||
return function(err) {
|
return function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
@ -268,10 +240,10 @@ fs.access = function(path, mode, callback) {
|
|||||||
if (typeof mode === 'function') {
|
if (typeof mode === 'function') {
|
||||||
callback = mode;
|
callback = mode;
|
||||||
mode = fs.F_OK;
|
mode = fs.F_OK;
|
||||||
} else if (typeof callback !== 'function') {
|
|
||||||
throw new TypeError('"callback" argument must be a function');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback = makeCallback(callback);
|
||||||
|
|
||||||
if (handleError((path = getPathFromURL(path)), callback))
|
if (handleError((path = getPathFromURL(path)), callback))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -280,7 +252,7 @@ fs.access = function(path, mode, callback) {
|
|||||||
|
|
||||||
mode = mode | 0;
|
mode = mode | 0;
|
||||||
var req = new FSReqWrap();
|
var req = new FSReqWrap();
|
||||||
req.oncomplete = makeCallback(callback);
|
req.oncomplete = callback;
|
||||||
binding.access(pathModule._makeLong(path), mode, req);
|
binding.access(pathModule._makeLong(path), mode, req);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
test/fixtures/test-fs-readfile-error.js
vendored
2
test/fixtures/test-fs-readfile-error.js
vendored
@ -19,4 +19,4 @@
|
|||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
require('fs').readFile('/'); // throws EISDIR
|
require('fs').readFileSync('/'); // throws EISDIR
|
||||||
|
@ -87,11 +87,11 @@ assert.throws(() => {
|
|||||||
|
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
fs.access(__filename, fs.F_OK);
|
fs.access(__filename, fs.F_OK);
|
||||||
}, /^TypeError: "callback" argument must be a function$/);
|
}, common.expectsError({code: 'ERR_INVALID_CALLBACK'}));
|
||||||
|
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
fs.access(__filename, fs.F_OK, {});
|
fs.access(__filename, fs.F_OK, {});
|
||||||
}, /^TypeError: "callback" argument must be a function$/);
|
}, common.expectsError({code: 'ERR_INVALID_CALLBACK'}));
|
||||||
|
|
||||||
assert.doesNotThrow(() => {
|
assert.doesNotThrow(() => {
|
||||||
fs.accessSync(__filename);
|
fs.accessSync(__filename);
|
||||||
|
@ -23,14 +23,14 @@ fs.link(srcPath, dstPath, common.mustCall(callback));
|
|||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
function() {
|
function() {
|
||||||
fs.link();
|
fs.link(undefined, undefined, common.mustNotCall());
|
||||||
},
|
},
|
||||||
/src must be a string or Buffer/
|
/src must be a string or Buffer/
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
function() {
|
function() {
|
||||||
fs.link('abc');
|
fs.link('abc', undefined, common.mustNotCall());
|
||||||
},
|
},
|
||||||
/dest must be a string or Buffer/
|
/dest must be a string or Buffer/
|
||||||
);
|
);
|
||||||
|
@ -2,11 +2,10 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const cbTypeError = /^TypeError: "callback" argument must be a function$/;
|
const cbTypeError = common.expectsError({code: 'ERR_INVALID_CALLBACK'});
|
||||||
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
||||||
|
|
||||||
const { sep } = require('path');
|
const { sep } = require('path');
|
||||||
const warn = 'Calling an asynchronous function without callback is deprecated.';
|
|
||||||
|
|
||||||
common.refreshTmpDir();
|
common.refreshTmpDir();
|
||||||
|
|
||||||
@ -17,11 +16,6 @@ function testMakeCallback(cb) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
common.expectWarning('DeprecationWarning', warn);
|
|
||||||
|
|
||||||
// Passing undefined/nothing calls rethrow() internally, which emits a warning
|
|
||||||
assert.doesNotThrow(testMakeCallback());
|
|
||||||
|
|
||||||
function invalidCallbackThrowsTests() {
|
function invalidCallbackThrowsTests() {
|
||||||
callbackThrowValues.forEach((value) => {
|
callbackThrowValues.forEach((value) => {
|
||||||
assert.throws(testMakeCallback(value), cbTypeError);
|
assert.throws(testMakeCallback(value), cbTypeError);
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const cbTypeError = /^TypeError: "callback" argument must be a function$/;
|
const cbTypeError = common.expectsError({code: 'ERR_INVALID_CALLBACK'});
|
||||||
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
||||||
const warn = 'Calling an asynchronous function without callback is deprecated.';
|
|
||||||
|
|
||||||
function testMakeStatsCallback(cb) {
|
function testMakeStatsCallback(cb) {
|
||||||
return function() {
|
return function() {
|
||||||
@ -13,14 +12,9 @@ function testMakeStatsCallback(cb) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
common.expectWarning('DeprecationWarning', warn);
|
|
||||||
|
|
||||||
// Verify the case where a callback function is provided
|
// Verify the case where a callback function is provided
|
||||||
assert.doesNotThrow(testMakeStatsCallback(common.noop));
|
assert.doesNotThrow(testMakeStatsCallback(common.noop));
|
||||||
|
|
||||||
// Passing undefined/nothing calls rethrow() internally, which emits a warning
|
|
||||||
assert.doesNotThrow(testMakeStatsCallback());
|
|
||||||
|
|
||||||
function invalidCallbackThrowsTests() {
|
function invalidCallbackThrowsTests() {
|
||||||
callbackThrowValues.forEach((value) => {
|
callbackThrowValues.forEach((value) => {
|
||||||
assert.throws(testMakeStatsCallback(value), cbTypeError);
|
assert.throws(testMakeStatsCallback(value), cbTypeError);
|
||||||
|
@ -29,8 +29,3 @@ fs.mkdtemp(path.join(common.tmpDir, 'bar.'), common.mustCall(handler));
|
|||||||
// Same test as above, but making sure that passing an options object doesn't
|
// Same test as above, but making sure that passing an options object doesn't
|
||||||
// affect the way the callback function is handled.
|
// affect the way the callback function is handled.
|
||||||
fs.mkdtemp(path.join(common.tmpDir, 'bar.'), {}, common.mustCall(handler));
|
fs.mkdtemp(path.join(common.tmpDir, 'bar.'), {}, common.mustCall(handler));
|
||||||
|
|
||||||
// Making sure that not passing a callback doesn't crash, as a default function
|
|
||||||
// is passed internally.
|
|
||||||
assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));
|
|
||||||
assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-'), {}));
|
|
||||||
|
@ -46,7 +46,7 @@ function test(env, cb) {
|
|||||||
|
|
||||||
test({ NODE_DEBUG: '' }, common.mustCall((data) => {
|
test({ NODE_DEBUG: '' }, common.mustCall((data) => {
|
||||||
assert(/EISDIR/.test(data));
|
assert(/EISDIR/.test(data));
|
||||||
assert(!/test-fs-readfile-error/.test(data));
|
assert(/test-fs-readfile-error/.test(data));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => {
|
test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
fs.write(null, Buffer.allocUnsafe(1), 0, 1);
|
fs.write(null, Buffer.allocUnsafe(1), 0, 1, common.mustNotCall());
|
||||||
}, /TypeError/);
|
}, /TypeError/);
|
||||||
|
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
fs.write(null, '1', 0, 1);
|
fs.write(null, '1', 0, 1, common.mustNotCall());
|
||||||
}, /TypeError/);
|
}, /TypeError/);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user