Skip to content
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

Conversation

thefourtheye
Copy link
Contributor

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 thefourtheye added fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version. labels Jul 27, 2016
@thefourtheye
Copy link
Contributor Author

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.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: are deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@MylesBorins
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@thefourtheye thefourtheye mentioned this pull request Jul 28, 2016
2 tasks
@claudiorodriguez
Copy link
Contributor

citgm failing:

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

@thefourtheye
Copy link
Contributor Author

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

@targos
Copy link
Member

targos commented Jul 28, 2016

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

make test-npm

@thefourtheye
Copy link
Contributor Author

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.

@@ -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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just compare cb === undefined.

@jasnell
Copy link
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
Copy link
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
Copy link
Member

jasnell commented Aug 9, 2016

ping @thefourtheye

@thefourtheye thefourtheye force-pushed the fs-warn-instead-of-throwing branch 2 times, most recently from 3b0ece0 to c2d6f53 Compare August 12, 2016 06:48
@thefourtheye
Copy link
Contributor Author

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.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are deprecated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even better, make it singular.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silverwind Done.

@jasnell
Copy link
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
Copy link
Contributor Author

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

@jasnell
Copy link
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 fs-warn-instead-of-throwing branch 2 times, most recently from fe1b569 to c8b8d4b Compare August 19, 2016 02:13
@jasnell
Copy link
Member

jasnell commented Aug 26, 2016

LGTM with a nit if CI is green.

This patch issues a deprecation warning, if an asynchronous function
is called without a callback function.
@thefourtheye
Copy link
Contributor Author

@yorkie
Copy link
Contributor

yorkie commented Aug 26, 2016

LGTM if CI is green

@jasnell
Copy link
Member

jasnell commented Aug 26, 2016

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

@addaleax
Copy link
Member

LGTM

@thefourtheye
Copy link
Contributor Author

Thanks for the review people. Landed in f8f283b

@thefourtheye thefourtheye deleted the fs-warn-instead-of-throwing branch August 27, 2016 07:18
thefourtheye added a commit that referenced this pull request Aug 27, 2016
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 mentioned this pull request Oct 14, 2016
jasnell added a commit to jasnell/node that referenced this pull request Oct 24, 2016
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
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
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
    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>
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants