Revert "fs: Revert throw on invalid callbacks"
This reverts commit 8250bfd1e5188d5dada58aedf7a991e959d5eaa9. PR-URL: https://github.com/nodejs/node/pull/18668 Refs: https://github.com/nodejs/node/pull/12562 Refs: https://github.com/nodejs/node/pull/12976 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
This commit is contained in:
parent
009e41826f
commit
e9f2cecf1a
@ -162,9 +162,10 @@ explicitly via error event handlers set on the domain instead.
|
||||
<a id="DEP0013"></a>
|
||||
### DEP0013: fs asynchronous 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 throws a `TypeError`
|
||||
REPLACEME onwards. Refer: [PR 12562](https://github.com/nodejs/node/pull/12562)
|
||||
|
||||
<a id="DEP0014"></a>
|
||||
### DEP0014: fs.read legacy String interface
|
||||
|
180
doc/api/fs.md
180
doc/api/fs.md
@ -819,10 +819,14 @@ try {
|
||||
<!-- YAML
|
||||
added: v0.6.7
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7831
|
||||
description: The passed `options` object will never be modified.
|
||||
@ -935,6 +939,10 @@ try {
|
||||
<!-- YAML
|
||||
added: v0.1.30
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -942,7 +950,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1018,6 +1026,10 @@ See also: chmod(2)
|
||||
<!-- YAML
|
||||
added: v0.1.97
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -1025,7 +1037,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1062,10 +1074,14 @@ See also: chown(2)
|
||||
<!-- YAML
|
||||
added: v0.0.2
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1444,10 +1460,14 @@ a callback.)
|
||||
<!-- YAML
|
||||
added: v0.4.7
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1472,10 +1492,14 @@ Synchronous fchmod(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.4.7
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1502,10 +1526,14 @@ Synchronous fchown(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.1.96
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1528,10 +1556,14 @@ Synchronous fdatasync(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.1.95
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1557,10 +1589,14 @@ Synchronous fstat(2). Returns an instance of [`fs.Stats`][].
|
||||
<!-- YAML
|
||||
added: v0.1.96
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1583,10 +1619,14 @@ Synchronous fsync(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.8.6
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1652,10 +1692,14 @@ Synchronous ftruncate(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.4.2
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/2387
|
||||
description: Numeric strings, `NaN` and `Infinity` are now allowed
|
||||
@ -1694,10 +1738,14 @@ Synchronous version of [`fs.futimes()`][]. Returns `undefined`.
|
||||
<!-- YAML
|
||||
deprecated: v0.4.7
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1724,10 +1772,14 @@ Synchronous lchmod(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
deprecated: v0.4.7
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1754,6 +1806,10 @@ Synchronous lchown(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.1.31
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `existingPath` and `newPath` parameters can be WHATWG
|
||||
@ -1762,7 +1818,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1793,6 +1849,10 @@ Synchronous link(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.1.30
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -1800,7 +1860,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1832,6 +1892,10 @@ Synchronous lstat(2). Returns an instance of [`fs.Stats`][].
|
||||
<!-- YAML
|
||||
added: v0.1.8
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -1839,7 +1903,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -1874,10 +1938,14 @@ See also: mkdir(2)
|
||||
<!-- YAML
|
||||
added: v5.10.0
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/6828
|
||||
description: The `callback` parameter is optional now.
|
||||
@ -2130,6 +2198,10 @@ a Promise for an object with `bytesRead` and `buffer` properties.
|
||||
<!-- YAML
|
||||
added: v0.1.8
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -2137,7 +2209,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/5616
|
||||
description: The `options` parameter was added.
|
||||
@ -2186,6 +2258,10 @@ the filenames returned will be passed as `Buffer` objects.
|
||||
<!-- YAML
|
||||
added: v0.1.29
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -2193,7 +2269,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/3740
|
||||
description: The `callback` will always be called with `null` as the `error`
|
||||
@ -2296,6 +2372,10 @@ fs.readFileSync('<directory>'); // => null, <data>
|
||||
<!-- YAML
|
||||
added: v0.1.31
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -2303,7 +2383,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -2365,6 +2445,10 @@ Synchronous version of [`fs.read()`][]. Returns the number of `bytesRead`.
|
||||
<!-- YAML
|
||||
added: v0.1.31
|
||||
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: v8.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/13028
|
||||
description: Pipe/Socket resolve support was added.
|
||||
@ -2375,7 +2459,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7899
|
||||
description: Calling `realpath` now works again for various edge cases
|
||||
@ -2518,6 +2602,10 @@ this restriction.
|
||||
<!-- YAML
|
||||
added: v0.0.2
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `oldPath` and `newPath` parameters can be WHATWG `URL`
|
||||
@ -2526,7 +2614,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -2557,6 +2645,10 @@ Synchronous rename(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.0.2
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameters can be a WHATWG `URL` object using
|
||||
@ -2564,7 +2656,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -2598,6 +2690,10 @@ on Windows and an `ENOTDIR` error on POSIX.
|
||||
<!-- YAML
|
||||
added: v0.0.2
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -2605,7 +2701,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -2694,10 +2790,14 @@ Synchronous symlink(2). Returns `undefined`.
|
||||
<!-- YAML
|
||||
added: v0.8.6
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -2730,6 +2830,10 @@ in the future.
|
||||
<!-- YAML
|
||||
added: v0.0.2
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using `file:`
|
||||
@ -2737,7 +2841,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -2798,6 +2902,10 @@ and `fs.unwatchFile()` when possible.
|
||||
<!-- YAML
|
||||
added: v0.4.2
|
||||
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: v8.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/11919
|
||||
description: "`NaN`, `Infinity`, and `-Infinity` are no longer valid time
|
||||
@ -2809,7 +2917,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/2387
|
||||
description: Numeric strings, `NaN` and `Infinity` are now allowed
|
||||
@ -3031,6 +3139,10 @@ This happens when:
|
||||
<!-- YAML
|
||||
added: v0.0.2
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10382
|
||||
description: The `buffer` parameter can now be a `Uint8Array`.
|
||||
@ -3040,7 +3152,7 @@ changes:
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -3080,13 +3192,17 @@ the end of the file.
|
||||
<!-- YAML
|
||||
added: v0.11.5
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/7856
|
||||
description: The `position` parameter is optional now.
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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}
|
||||
@ -3127,13 +3243,17 @@ the end of the file.
|
||||
<!-- YAML
|
||||
added: v0.1.29
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/10382
|
||||
description: The `data` parameter can now be a `Uint8Array`.
|
||||
- version: v7.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/7897
|
||||
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
|
||||
pr-url: https://github.com/nodejs/node/pull/3163
|
||||
description: The `file` parameter can be a file descriptor now.
|
||||
|
54
lib/fs.js
54
lib/fs.js
@ -77,7 +77,6 @@ const { kMaxLength } = require('buffer');
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
|
||||
const errnoException = errors.errnoException;
|
||||
|
||||
let truncateWarn = true;
|
||||
@ -106,46 +105,17 @@ function handleErrorFromBinding(ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(joyeecheung): explore how the deprecation could be solved via linting
|
||||
// rules. See https://github.com/nodejs/node/pull/12976
|
||||
function rethrow() {
|
||||
process.emitWarning(
|
||||
'Calling an asynchronous function without callback is deprecated.',
|
||||
'DeprecationWarning', 'DEP0013', rethrow
|
||||
);
|
||||
|
||||
// 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) {
|
||||
return typeof cb === 'function' ? cb : rethrow();
|
||||
if (typeof cb === 'function')
|
||||
return cb;
|
||||
|
||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||
}
|
||||
|
||||
// Ensure that callbacks run in the global context. Only use this function
|
||||
// for callbacks that are passed to the binding layer, callbacks that are
|
||||
// invoked from JS already run in the proper scope.
|
||||
function makeCallback(cb) {
|
||||
if (cb === undefined) {
|
||||
return rethrow();
|
||||
}
|
||||
|
||||
if (typeof cb !== 'function') {
|
||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||
}
|
||||
@ -159,10 +129,6 @@ function makeCallback(cb) {
|
||||
// an optimization, since the data passed back to the callback needs to be
|
||||
// transformed anyway.
|
||||
function makeStatsCallback(cb) {
|
||||
if (cb === undefined) {
|
||||
return rethrow();
|
||||
}
|
||||
|
||||
if (typeof cb !== 'function') {
|
||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||
}
|
||||
@ -191,8 +157,6 @@ fs.access = function(path, mode, callback) {
|
||||
if (typeof mode === 'function') {
|
||||
callback = mode;
|
||||
mode = fs.F_OK;
|
||||
} else if (typeof callback !== 'function') {
|
||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||
}
|
||||
|
||||
path = getPathFromURL(path);
|
||||
@ -218,16 +182,8 @@ fs.accessSync = function(path, mode) {
|
||||
handleErrorFromBinding(ctx);
|
||||
};
|
||||
|
||||
// fs.exists never throws even when the arguments are invalid - if there is
|
||||
// a callback it would invoke it with false, otherwise it emits a warning
|
||||
// (see the comments of rethrow()).
|
||||
// This is to bring it inline with fs.existsSync, which never throws.
|
||||
// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
|
||||
fs.exists = function(path, callback) {
|
||||
if (typeof callback !== 'function') {
|
||||
rethrow();
|
||||
return;
|
||||
}
|
||||
maybeCallback(callback);
|
||||
|
||||
function suppressedCallback(err) {
|
||||
callback(err ? false : true);
|
||||
|
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
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
require('fs').readFile('/'); // throws EISDIR
|
||||
require('fs').readFileSync('/'); // throws EISDIR
|
||||
|
@ -80,7 +80,8 @@ fs.access(readOnlyFile, fs.F_OK | fs.R_OK, common.mustCall((err) => {
|
||||
assert.ifError(err);
|
||||
}));
|
||||
|
||||
fs.access(readOnlyFile, fs.W_OK, common.mustCall((err) => {
|
||||
fs.access(readOnlyFile, fs.W_OK, common.mustCall(function(err) {
|
||||
assert.strictEqual(this, undefined);
|
||||
if (hasWriteAccessForReadonlyFile) {
|
||||
assert.ifError(err);
|
||||
} else {
|
||||
|
@ -146,12 +146,9 @@ 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(tmpdir.path, 'append6.txt');
|
||||
const warn = 'Calling an asynchronous function without callback is deprecated.';
|
||||
common.expectWarning('DeprecationWarning', warn);
|
||||
fs.appendFile(filename6, console.log);
|
||||
assert.throws(
|
||||
() => fs.appendFile(join(tmpdir.path, 'append6.txt'), console.log),
|
||||
{ code: 'ERR_INVALID_CALLBACK' });
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.strictEqual(12, ncallbacks);
|
||||
|
@ -26,10 +26,9 @@ const fs = require('fs');
|
||||
const { URL } = require('url');
|
||||
const f = __filename;
|
||||
|
||||
// Only warnings are emitted when the callback is invalid
|
||||
fs.exists(f);
|
||||
fs.exists();
|
||||
fs.exists(f, {});
|
||||
assert.throws(() => fs.exists(f), { code: 'ERR_INVALID_CALLBACK' });
|
||||
assert.throws(() => fs.exists(), { code: 'ERR_INVALID_CALLBACK' });
|
||||
assert.throws(() => fs.exists(f, {}), { code: 'ERR_INVALID_CALLBACK' });
|
||||
|
||||
fs.exists(f, common.mustCall(function(y) {
|
||||
assert.strictEqual(y, true);
|
||||
|
@ -44,7 +44,7 @@ const fs = require('fs');
|
||||
|
||||
// Check for mode values range
|
||||
const modeUpperBoundaryValue = 0o777;
|
||||
fs.fchmod(1, modeUpperBoundaryValue);
|
||||
fs.fchmod(1, modeUpperBoundaryValue, common.mustCall());
|
||||
fs.fchmodSync(1, modeUpperBoundaryValue);
|
||||
|
||||
// umask of 0o777 is equal to 775
|
||||
|
@ -4,7 +4,6 @@ const fs = require('fs');
|
||||
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
||||
|
||||
const { sep } = require('path');
|
||||
const warn = 'Calling an asynchronous function without callback is deprecated.';
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
tmpdir.refresh();
|
||||
@ -16,11 +15,6 @@ function testMakeCallback(cb) {
|
||||
};
|
||||
}
|
||||
|
||||
common.expectWarning('DeprecationWarning', warn);
|
||||
|
||||
// Passing undefined/nothing calls rethrow() internally, which emits a warning
|
||||
testMakeCallback()();
|
||||
|
||||
function invalidCallbackThrowsTests() {
|
||||
callbackThrowValues.forEach((value) => {
|
||||
common.expectsError(testMakeCallback(value), {
|
||||
|
@ -2,7 +2,6 @@
|
||||
const common = require('../common');
|
||||
const fs = require('fs');
|
||||
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
||||
const warn = 'Calling an asynchronous function without callback is deprecated.';
|
||||
|
||||
function testMakeStatsCallback(cb) {
|
||||
return function() {
|
||||
@ -11,14 +10,9 @@ function testMakeStatsCallback(cb) {
|
||||
};
|
||||
}
|
||||
|
||||
common.expectWarning('DeprecationWarning', warn);
|
||||
|
||||
// Verify the case where a callback function is provided
|
||||
testMakeStatsCallback(common.mustCall())();
|
||||
|
||||
// Passing undefined/nothing calls rethrow() internally, which emits a warning
|
||||
testMakeStatsCallback()();
|
||||
|
||||
function invalidCallbackThrowsTests() {
|
||||
callbackThrowValues.forEach((value) => {
|
||||
common.expectsError(testMakeStatsCallback(value), {
|
||||
|
@ -29,8 +29,3 @@ fs.mkdtemp(path.join(tmpdir.path, 'bar.'), common.mustCall(handler));
|
||||
// Same test as above, but making sure that passing an options object doesn't
|
||||
// affect the way the callback function is handled.
|
||||
fs.mkdtemp(path.join(tmpdir.path, 'bar.'), {}, common.mustCall(handler));
|
||||
|
||||
// Making sure that not passing a callback doesn't crash, as a default function
|
||||
// is passed internally.
|
||||
fs.mkdtemp(path.join(tmpdir.path, 'bar-'));
|
||||
fs.mkdtemp(path.join(tmpdir.path, 'bar-'), {});
|
||||
|
@ -48,7 +48,7 @@ function test(env, cb) {
|
||||
|
||||
test({ NODE_DEBUG: '' }, common.mustCall((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) => {
|
||||
@ -57,7 +57,7 @@ test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => {
|
||||
}));
|
||||
|
||||
common.expectsError(
|
||||
() => { fs.readFile(() => {}); },
|
||||
() => { fs.readFile(() => {}, common.mustNotCall()); },
|
||||
{
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "path" argument must be one of type string, Buffer, or URL',
|
||||
|
@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
|
||||
assert.throws(function() {
|
||||
fs.write(null, Buffer.allocUnsafe(1), 0, 1);
|
||||
fs.write(null, Buffer.allocUnsafe(1), 0, 1, common.mustNotCall());
|
||||
}, /TypeError/);
|
||||
|
||||
assert.throws(function() {
|
||||
fs.write(null, '1', 0, 1);
|
||||
fs.write(null, '1', 0, 1, common.mustNotCall());
|
||||
}, /TypeError/);
|
||||
|
Loading…
x
Reference in New Issue
Block a user