New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: warn instead of throwing if no callback #7897

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
10 participants
@thefourtheye
Contributor

thefourtheye commented Jul 27, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected 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

@thefourtheye

This comment has been minimized.

Contributor

thefourtheye commented Jul 27, 2016

@MylesBorins

View changes

lib/fs.js Outdated
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.';

This comment has been minimized.

@MylesBorins

MylesBorins Jul 27, 2016

Member

nit: are deprecated

This comment has been minimized.

@thefourtheye

thefourtheye Jul 28, 2016

Contributor

Done.

@MylesBorins

This comment has been minimized.

Member

MylesBorins commented Jul 27, 2016

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

@yorkie

View changes

lib/fs.js Outdated
@@ -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

This comment has been minimized.

@yorkie

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

This comment has been minimized.

@thefourtheye

thefourtheye Jul 28, 2016

Contributor

Done.

@yorkie

View changes

lib/fs.js Outdated
@@ -40,6 +41,8 @@ const isWindows = process.platform === 'win32';
const errnoException = util._errnoException;
const NOOP = function() {};

This comment has been minimized.

@yorkie

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.

This comment has been minimized.

@thefourtheye

thefourtheye Jul 28, 2016

Contributor

Done.

@thefourtheye thefourtheye referenced this pull request Jul 28, 2016

Closed

Revert fs changes #7846

2 of 2 tasks complete
@claudiorodriguez

This comment has been minimized.

Member

claudiorodriguez commented Jul 28, 2016

citgm failing:

+ npm set progress=false
...
npm ERR! npm  v3.10.3
...
npm ERR! cb is not a function
@thefourtheye

This comment has been minimized.

Contributor

thefourtheye commented Jul 28, 2016

Do you guys know how I can locally reproduce this problem?

@targos

This comment has been minimized.

Member

targos commented Jul 28, 2016

Do you guys know how I can locally reproduce this problem?

make test-npm

@thefourtheye

This comment has been minimized.

Contributor

thefourtheye commented Jul 28, 2016

I think when npm/npm#13497 lands and gets integrated to Node.js Core, this problem will be solved.

Wait, this should not fail though. I'll investigate further, a little later.

@cjihrig

View changes

lib/fs.js Outdated
@@ -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') {

This comment has been minimized.

@cjihrig

cjihrig Aug 1, 2016

Contributor

You can just compare cb === undefined.

@RReverser

View changes

lib/fs.js Outdated
@@ -40,6 +41,8 @@ const isWindows = process.platform === 'win32';
const errnoException = util._errnoException;
const noop = function() {};
var printDeprecation;
try {
printDeprecation = require('internal/util').printDeprecationMessage;

This comment has been minimized.

@RReverser

RReverser Aug 2, 2016

Member

You can put var right here (to avoid duplication) or change top-level declaration to let.

@jasnell

View changes

lib/fs.js Outdated
// 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.';

This comment has been minimized.

@jasnell

jasnell Aug 4, 2016

Member

I'm not sure this additional part about --trace-deprecation is necessary but can live with it.

@jasnell

View changes

lib/fs.js Outdated
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.';

This comment has been minimized.

@jasnell

jasnell Aug 4, 2016

Member

s/async/Asynchronous

@jasnell

This comment has been minimized.

Member

jasnell commented Aug 4, 2016

A test case validating that the deprecation warning is emitted would be good. With that added this LGTM

@addaleax

This comment has been minimized.

Member

addaleax commented Aug 4, 2016

@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!

@addaleax addaleax added this to the 7.0.0 milestone Aug 8, 2016

@jasnell

This comment has been minimized.

Member

jasnell commented Aug 9, 2016

@thefourtheye thefourtheye force-pushed the thefourtheye:fs-warn-instead-of-throwing branch 2 times, most recently Aug 12, 2016

@thefourtheye

This comment has been minimized.

Contributor

thefourtheye commented Aug 12, 2016

Updated with the deprecation warning alone. PTAL people.

@silverwind

View changes

lib/fs.js Outdated
@@ -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.';

This comment has been minimized.

@silverwind

silverwind Aug 12, 2016

Contributor

are deprecated

This comment has been minimized.

@silverwind

silverwind Aug 12, 2016

Contributor

or even better, make it singular.

This comment has been minimized.

@thefourtheye
@jasnell

This comment has been minimized.

Member

jasnell commented Aug 18, 2016

LGTM with @silverwind's nit addressed

Actually, let me take that back... this uses internal which means it would end up being blocked by the graceful-fs issues. Instead of using printDeprecationNotice, this should be modified to use the new process.emitWarning() API.

For instance:

process.emitWarning(depMessage, 'DeprecationWarning');

By passing DeprecationWarning as the second argument, this will be handled as a normal deprecation.

ping @thefourtheye

@thefourtheye thefourtheye force-pushed the thefourtheye:fs-warn-instead-of-throwing branch Aug 19, 2016

@thefourtheye

This comment has been minimized.

Contributor

thefourtheye commented Aug 19, 2016

@jasnell I modified it to use printDeprecation function which already takes care of the graceful-fs problem. Is that okay?

@jasnell

This comment has been minimized.

Member

jasnell commented Aug 19, 2016

@thefourtheye ... That partially handles it. See #8166. I'm attempting to move things away from using the internal util printDeprecationMessage.

@thefourtheye thefourtheye force-pushed the thefourtheye:fs-warn-instead-of-throwing branch 2 times, most recently Aug 19, 2016

@jasnell

View changes

test/parallel/test-fs-make-callback.js Outdated
process.once('warning', common.mustCall((warning) => {
assert.strictEqual(
warning.message,
'calling an asynchronous function without callback is deprecated.'

This comment has been minimized.

@jasnell

jasnell Aug 26, 2016

Member

nit: s/calling/Calling

This comment has been minimized.

@thefourtheye

thefourtheye Aug 26, 2016

Contributor

Ack.

@jasnell

This comment has been minimized.

Member

jasnell commented Aug 26, 2016

LGTM with a nit if CI is green.

fs: warn if no callback is passed to async calls
This patch issues a deprecation warning, if an asynchronous function
is called without a callback function.

@thefourtheye thefourtheye force-pushed the thefourtheye:fs-warn-instead-of-throwing branch to 3e97e2c Aug 26, 2016

@thefourtheye

This comment has been minimized.

Contributor

thefourtheye commented Aug 26, 2016

@yorkie

This comment has been minimized.

Member

yorkie commented Aug 26, 2016

LGTM if CI is green

@jasnell

This comment has been minimized.

Member

jasnell commented Aug 26, 2016

@nodejs/ctc ... as a semver-major this needs another CTC signoff...

@addaleax

This comment has been minimized.

Member

addaleax commented Aug 27, 2016

LGTM

@thefourtheye

This comment has been minimized.

Contributor

thefourtheye commented Aug 27, 2016

Thanks for the review people. Landed in f8f283b

@thefourtheye thefourtheye deleted the thefourtheye:fs-warn-instead-of-throwing branch Aug 27, 2016

thefourtheye added a commit that referenced this pull request Aug 27, 2016

fs: warn if no callback is passed to async calls
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>

@jasnell jasnell referenced this pull request Oct 14, 2016

Closed

v7.0.0 Proposal #9099

jasnell added a commit to jasnell/node that referenced this pull request Oct 24, 2016

2016-10-25, Version 7.0.0 (Current)
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).

jasnell added a commit that referenced this pull request Oct 25, 2016

2016-10-25, Version 7.0.0 (Current)
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

jasnell added a commit that referenced this pull request Oct 25, 2016

2016-10-25, Version 7.0.0 (Current)
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

imyller added a commit to imyller/meta-nodejs that referenced this pull request Oct 25, 2016

2016-10-25, Version 7.0.0 (Current)
    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>

@goliney goliney referenced this pull request Oct 25, 2016

Merged

Node v7 support #174

@gibfahn gibfahn referenced this pull request Jun 15, 2017

Closed

Auditing for 6.11.1 #230

2 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment