fs: warn instead of throwing if no callback #7897
Conversation
if (typeof cb !== 'function') { | ||
if (typeof cb === 'undefined') { | ||
// TODO throw error instead of deprecation warning in v8.0.0 | ||
let m = 'async function calls without valid callbacks is deprecated.'; |
MylesBorins
Jul 27, 2016
Member
nit: are deprecated
nit: are deprecated
thefourtheye
Jul 28, 2016
Author
Contributor
Done.
Done.
citgm: https://ci.nodejs.org/view/Node.js-citgm/job/thealphanerd-smoker-xunit/39/ I like the approach here. +1 for this over the revert |
@@ -95,7 +98,14 @@ function sanitizeFD(fd) { | |||
// 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 (typeof cb !== 'function') { | |||
if (typeof cb === 'undefined') { | |||
// TODO throw error instead of deprecation warning in v8.0.0 |
yorkie
Jul 27, 2016
Member
I did remember the other TODO/FIXME/etc.'s format is not like this, suggest:
// TODO(thefourtheye): throw error instead of deprecation warning in v8.0.0
I did remember the other TODO/FIXME/etc.'s format is not like this, suggest:
// TODO(thefourtheye): throw error instead of deprecation warning in v8.0.0
thefourtheye
Jul 28, 2016
Author
Contributor
Done.
Done.
@@ -40,6 +41,8 @@ const isWindows = process.platform === 'win32'; | |||
|
|||
const errnoException = util._errnoException; | |||
|
|||
const NOOP = function() {}; |
yorkie
Jul 27, 2016
Member
noop
in lower case would be better that keeps consistent with https://github.com/nodejs/node/search?utf8=%E2%9C%93&q=NOOP.
noop
in lower case would be better that keeps consistent with https://github.com/nodejs/node/search?utf8=%E2%9C%93&q=NOOP.
thefourtheye
Jul 28, 2016
Author
Contributor
Done.
Done.
citgm failing:
|
Do you guys know how I can locally reproduce this problem? |
|
Wait, this should not fail though. I'll investigate further, a little later. |
@@ -95,7 +98,15 @@ function sanitizeFD(fd) { | |||
// 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 (typeof cb !== 'function') { | |||
if (typeof cb === 'undefined') { |
cjihrig
Aug 1, 2016
Contributor
You can just compare cb === undefined
.
You can just compare cb === undefined
.
@@ -40,6 +41,8 @@ const isWindows = process.platform === 'win32'; | |||
|
|||
const errnoException = util._errnoException; | |||
|
|||
const noop = function() {}; | |||
|
|||
var printDeprecation; | |||
try { | |||
printDeprecation = require('internal/util').printDeprecationMessage; |
RReverser
Aug 2, 2016
Member
You can put var
right here (to avoid duplication) or change top-level declaration to let
.
You can put var
right here (to avoid duplication) or change top-level declaration to let
.
// Refer the discussion: https://github.com/nodejs/node/pull/7846 | ||
let m = 'async function calls without valid callbacks are deprecated.'; | ||
if (!process.traceDeprecation) | ||
m += ' Use --trace-deprecation to find the function responsible.'; |
jasnell
Aug 4, 2016
Member
I'm not sure this additional part about --trace-deprecation
is necessary but can live with it.
I'm not sure this additional part about --trace-deprecation
is necessary but can live with it.
if (typeof cb === 'undefined') { | ||
// TODO(thefourtheye): throw error instead of deprecation warning in v8.0.0 | ||
// Refer the discussion: https://github.com/nodejs/node/pull/7846 | ||
let m = 'async function calls without valid callbacks are deprecated.'; |
jasnell
Aug 4, 2016
Member
s/async/Asynchronous
s/async/Asynchronous
A test case validating that the deprecation warning is emitted would be good. With that added this LGTM |
@thefourtheye As expected, this conflicts now… I think it’s okay to apply the changes that got reverted here again (with the intention to squash in the warnings?). Sorry for the trouble the process is causing you! |
ping @thefourtheye |
Updated with the deprecation warning alone. PTAL people. |
@@ -112,10 +113,13 @@ function maybeCallback(cb) { | |||
// invoked from JS already run in the proper scope. | |||
function makeCallback(cb) { | |||
if (cb === undefined) { | |||
// TODO(thefourtheye) throw error instead of warning in major version > 7 | |||
let m = 'asynchronous function calls without callbacks is deprecated.'; |
silverwind
Aug 12, 2016
Contributor
are deprecated
are deprecated
silverwind
Aug 12, 2016
Contributor
or even better, make it singular.
or even better, make it singular.
Actually, let me take that back... this uses For instance: process.emitWarning(depMessage, 'DeprecationWarning'); By passing ping @thefourtheye |
@jasnell I modified it to use |
@thefourtheye ... That partially handles it. See #8166. I'm attempting to move things away from using the internal util printDeprecationMessage. |
LGTM with a nit if CI is green. |
This patch issues a deprecation warning, if an asynchronous function is called without a callback function.
3e97e2c
LGTM if CI is green |
@nodejs/ctc ... as a semver-major this needs another CTC signoff... |
LGTM |
Thanks for the review people. Landed in f8f283b |
This patch issues a deprecation warning, if an asynchronous function is called without a callback function. PR-URL: #7897 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Notable Changes: * Buffer * Passing invalid input to Buffer.byteLength will now throw an error [nodejs#8946](nodejs#8946). * Calling Buffer without new is now deprecated and will emit a process warning [nodejs#8169](nodejs#8169). * Passing a negative number to allocUnsafe will now throw an error [nodejs#7079](nodejs#7079). * Child Process * The fork and execFile methods now have stronger argument validation [nodejs#7399](nodejs#7399). * Cluster * The worker.suicide method is deprecated and will emit a process warning [nodejs#3747](nodejs#3747). * Deps * V8 has been updated to 5.4.500.36 [nodejs#8317](nodejs#8317), [nodejs#8852](nodejs#8852), [nodejs#9253](nodejs#9253). * NODE_MODULE_VERSION has been updated to 51 [nodejs#8808](nodejs#8808). * File System * A process warning is emitted if a callback is not passed to async file system methods [nodejs#7897](nodejs#7897). * Intl * Intl.v8BreakIterator constructor has been deprecated and will emit a process warning [nodejs#8908](nodejs#8908). * Promises * Unhandled Promise rejections have been deprecated and will emit a process warning [nodejs#8217](nodejs#8217). * Punycode * The `punycode` module has been deprecated [nodejs#7941](nodejs#7941). * URL * An Experimental WHATWG URL Parser has been introduced [nodejs#7448](nodejs#7448).
Notable Changes: * Buffer * Passing invalid input to Buffer.byteLength will now throw an error [#8946](#8946). * Calling Buffer without new is now deprecated and will emit a process warning [#8169](#8169). * Passing a negative number to allocUnsafe will now throw an error [#7079](#7079). * Child Process * The fork and execFile methods now have stronger argument validation [#7399](#7399). * Cluster * The worker.suicide method is deprecated and will emit a process warning [#3747](#3747). * Deps * V8 has been updated to 5.4.500.36 [#8317](#8317), [#8852](#8852), [#9253](#9253). * NODE_MODULE_VERSION has been updated to 51 [#8808](#8808). * File System * A process warning is emitted if a callback is not passed to async file system methods [#7897](#7897). * Intl * Intl.v8BreakIterator constructor has been deprecated and will emit a process warning [#8908](#8908). * Promises * Unhandled Promise rejections have been deprecated and will emit a process warning [#8217](#8217). * Punycode * The `punycode` module has been deprecated [#7941](#7941). * URL * An Experimental WHATWG URL Parser has been introduced [#7448](#7448). PR-URL: #9099
Notable Changes: * Buffer * Passing invalid input to Buffer.byteLength will now throw an error [#8946](#8946). * Calling Buffer without new is now deprecated and will emit a process warning [#8169](#8169). * Passing a negative number to allocUnsafe will now throw an error [#7079](#7079). * Child Process * The fork and execFile methods now have stronger argument validation [#7399](#7399). * Cluster * The worker.suicide method is deprecated and will emit a process warning [#3747](#3747). * Deps * V8 has been updated to 5.4.500.36 [#8317](#8317), [#8852](#8852), [#9253](#9253). * NODE_MODULE_VERSION has been updated to 51 [#8808](#8808). * File System * A process warning is emitted if a callback is not passed to async file system methods [#7897](#7897). * Intl * Intl.v8BreakIterator constructor has been deprecated and will emit a process warning [#8908](#8908). * Promises * Unhandled Promise rejections have been deprecated and will emit a process warning [#8217](#8217). * Punycode * The `punycode` module has been deprecated [#7941](#7941). * URL * An Experimental WHATWG URL Parser has been introduced [#7448](#7448). PR-URL: #9099
Notable Changes: * Buffer * Passing invalid input to Buffer.byteLength will now throw an error [#8946](nodejs/node#8946). * Calling Buffer without new is now deprecated and will emit a process warning [#8169](nodejs/node#8169). * Passing a negative number to allocUnsafe will now throw an error [#7079](nodejs/node#7079). * Child Process * The fork and execFile methods now have stronger argument validation [#7399](nodejs/node#7399). * Cluster * The worker.suicide method is deprecated and will emit a process warning [#3747](nodejs/node#3747). * Deps * V8 has been updated to 5.4.500.36 [#8317](nodejs/node#8317), [#8852](nodejs/node#8852), [#9253](nodejs/node#9253). * NODE_MODULE_VERSION has been updated to 51 [#8808](nodejs/node#8808). * File System * A process warning is emitted if a callback is not passed to async file system methods [#7897](nodejs/node#7897). * Intl * Intl.v8BreakIterator constructor has been deprecated and will emit a process warning [#8908](nodejs/node#8908). * Promises * Unhandled Promise rejections have been deprecated and will emit a process warning [#8217](nodejs/node#8217). * Punycode * The `punycode` module has been deprecated [#7941](nodejs/node#7941). * URL * An Experimental WHATWG URL Parser has been introduced [#7448](nodejs/node#7448). Signed-off-by: Ilkka Myller <ilkka.myller@nodefield.com>
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
fs
Description of change
9359de9
made sure that if no callback function is passed to asynchronous
functions, the system will throw.
But, this breaks a lot of existing modules including npm (Refer:
#7846). Till all the necessary
dependencies use the async functions properly, no module can work.
So, this patch issues a deprecation warning, instead of throwing and
the throwing behaviour will be restored in the next major release.
cc @ChALkeR @nodejs/collaborators @nodejs/ctc