| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Generally I like this change but I'm not really sure it's worth it given the amount of breakage it might cause in the wild. ---I tried running a smoke test but the CI gets frozen "Loading" when I attempt it - but I definitely think it's worth running in this case--- Smoke test: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/294/ Code changes themselves LGTM. |
Sorry, something went wrong.
|
I think the potential for ecosystem fallout is a bit too high to justify. Note that makeCallback() and maybeCallback() treat the callback argument differently. The former calls rethrow() when it strict-equals undefined, the latter does so for any falsy value. You could change makeCallback() to behave like maybeCallback() but that might introduce issues of its own. |
Sorry, something went wrong.
|
If we're going to break stuff, I'd rather break it to throw immediately when no callback is passed. Instead of throwing sometime in the future when the stack has been lost. |
Sorry, something went wrong.
|
@thealphanerd I looked at the smoke test output - it's green but looks like there are errors in the console output - can you PTAL? |
Sorry, something went wrong.
|
some of our production code would break with this change... get ready to cringe: that's because with a preflight stat verifying path or read/writability, it turns out fs read/writes done in the fire-and-forget fashion (never passing a callback) are not only fine but also reliable |
Sorry, something went wrong.
|
While not passing a callback might be equal to passing undefined, and most of the node API won't let me get away with this now, I liked when we had the option to ignore callbacks or their parameters. Occasionally program errors should be ignored, and the ability to not have to write an error handler for an inconsequential routine will reduce lines of code... for example, writing a noop() might be overkill The decision not to pass the callback should result in an immediate consequence, either throw immediately or its /dev/null. Passing a function, on the otherhand, indicates a clear statement about wanting to wait and handle that outcome. |
Sorry, something went wrong.
|
If we are going to make a semver-major change here can we please simply throw immediately? Throwing in the future is one of the dumbest designs in node today. |
Sorry, something went wrong.
There was a problem hiding this comment.
Should it not throw with arguments.length being 1?
Sorry, something went wrong.
|
+1 to throwing immediately. Thinking out loud: I do get the case where an explicit noop would be useful, however. I'm wondering if some form of sentinel value could be used to explicitly signal that the async method should simply not bother attempting to callback tho. A Symbol would work... fs.writeFile('/tmp/foo', 'hello there', fs.NoCallback);I dunno, just a thought. |
Sorry, something went wrong.
|
@jasnell Seems like a better option for a userland module to do? |
Sorry, something went wrong.
|
Okay, updated the PR to throw if the callback is not passed. PTAL. |
Sorry, something went wrong.
|
Sweet. The code change LGTM. Looks like we're missing test coverage checking if all the altered functions throw. Mind making sure there's a single check for each method to make sure it throws if no callback is passed? |
Sorry, something went wrong.
|
@trevnorris I included a test now to check if the functions fail when callback is not passed. |
Sorry, something went wrong.
There was a problem hiding this comment.
hmm... not thrilled about this approach. For instance, the following is technically not an incorrect way of calling the fs.access() function even if the extraneous arguments on the end aren't supported. This code, however, would fail:
fs.access('/some/path', () => {}, 'useless', 'arguments', 'here');
Sorry, something went wrong.
There was a problem hiding this comment.
@jasnell Perhaps I can traverse the arguments backwards and see if there is atleast one function object passed?
Sorry, something went wrong.
There was a problem hiding this comment.
It's a little verbose, but should be as simple as:
if (typeof mode === 'function') {
callback = mode;
mode = fs.F_OK;
}
if (typeof mode !== 'number' || Number.isNaN(mode)) {
throw new TypeError('mode must be a number');
}
if (typeof callback !== 'function') {
throw new TypeError('callback must be a function');
}
Sorry, something went wrong.
There was a problem hiding this comment.
If we are doing this, we should probably do the same for other methods as well.
Sorry, something went wrong.
There was a problem hiding this comment.
okay. I'd like that change, but let's keep that for another PR.
Sorry, something went wrong.
|
I agree with @jasnell's opinion on grabbing the last argument. Other than that LGTM. |
Sorry, something went wrong.
|
Still LGTM. With the note above that changing how arguments are parsed should go into another PR. |
Sorry, something went wrong.
The "fs" module has two functions called `maybeCallback` and `makeCallback`, as of now. The `maybeCallback` creates a default function to report errors, if the parameter passed is not a function object. Basically, if the callback is omitted in some cases, this function is used to create a default callback function. The `makeCallback`, OTOH, creates a default function only if the parameter passed is `undefined`, and if it is not a function object it will throw an `Error`. This patch removes the `maybeCallback` function and makes the callback function argument mandatory for all the async functions.
|
Rebased. CI Run: https://ci.nodejs.org/job/node-test-pull-request/3366/ |
Sorry, something went wrong.
The "fs" module has two functions called `maybeCallback` and `makeCallback`, as of now. The `maybeCallback` creates a default function to report errors, if the parameter passed is not a function object. Basically, if the callback is omitted in some cases, this function is used to create a default callback function. The `makeCallback`, OTOH, creates a default function only if the parameter passed is `undefined`, and if it is not a function object it will throw an `Error`. This patch removes the `maybeCallback` function and makes the callback function argument mandatory for all the async functions. PR-URL: #7168 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
|
oh hey all... looks like this broke npm set which in turn is breaking citgm on master /cc @nodejs/npm |
Sorry, something went wrong.
This reverts commit 9359de9. Original Commit Message: The "fs" module has two functions called `maybeCallback` and `makeCallback`, as of now. The `maybeCallback` creates a default function to report errors, if the parameter passed is not a function object. Basically, if the callback is omitted in some cases, this function is used to create a default callback function. The `makeCallback`, OTOH, creates a default function only if the parameter passed is `undefined`, and if it is not a function object it will throw an `Error`. This patch removes the `maybeCallback` function and makes the callback function argument mandatory for all the async functions. PR-URL: nodejs#7168 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Indeed, see npm/npm#13457 for further breakage that this causes in npm. What's the status on this? |
Sorry, something went wrong.
|
Status is that we will be reverting this specific change and taking a On Wednesday, July 27, 2016, Forrest L Norvell notifications@github.com
|
Sorry, something went wrong.
This reverts commit 9359de9. Original Commit Message: The "fs" module has two functions called `maybeCallback` and `makeCallback`, as of now. The `maybeCallback` creates a default function to report errors, if the parameter passed is not a function object. Basically, if the callback is omitted in some cases, this function is used to create a default callback function. The `makeCallback`, OTOH, creates a default function only if the parameter passed is `undefined`, and if it is not a function object it will throw an `Error`. This patch removes the `maybeCallback` function and makes the callback function argument mandatory for all the async functions. PR-URL: nodejs#7168 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This reverts commit 9359de9. Original Commit Message: The "fs" module has two functions called `maybeCallback` and `makeCallback`, as of now. The `maybeCallback` creates a default function to report errors, if the parameter passed is not a function object. Basically, if the callback is omitted in some cases, this function is used to create a default callback function. The `makeCallback`, OTOH, creates a default function only if the parameter passed is `undefined`, and if it is not a function object it will throw an `Error`. This patch removes the `maybeCallback` function and makes the callback function argument mandatory for all the async functions. PR-URL: #7168 Reviewed-By: Trevor Norris <trev.norris@gmail.com> PR-URL: #7846 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
| Back | FazBrowse Home | New Git URL |
Checklist
Affected core subsystem(s)
fs
Description of change
The "fs" module has two functions called maybeCallback and
makeCallback, as of now.
The maybeCallback creates a default function to report errors, if the
parameter passed is not a function object. Basically, if the callback
is omitted in some cases, this function is used to create a default
callback function.
The makeCallback, OTOH, creates a default function only if the
parameter passed is undefined, and if it is not a function object it
will throw an Error.
This patch removes the maybeCallback function and makes the callback
function argument mandatory for all the async versions.
cc @nodejs/collaborators