Uh oh!
There was an error while loading. Please reload this page.
fs: remove maybeCallback function - #7168
Conversation
thefourtheye
commented
Jun 5, 2016
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. |
bnoordhuis
commented
Jun 6, 2016
I think the potential for ecosystem fallout is a bit too high to justify. Note that You could change |
trevnorris
commented
Jun 6, 2016
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. |
benjamingr
commented
Jun 6, 2016
@thealphanerd I looked at the smoke test output - it's green but looks like there are errors in the console output - can you PTAL? |
reqshark
commented
Jun 6, 2016
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 |
benjamingr
commented
Jun 6, 2016
@reqshark wait, what?? |
reqshark
commented
Jun 6, 2016
While not passing a callback might be equal to passing 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 The decision not to pass the callback should result in an immediate consequence, either throw immediately or its |
trevnorris
commented
Jun 13, 2016
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. |
There was a problem hiding this comment.
Should it not throw with arguments.length being 1?
jasnell
commented
Jun 20, 2016
+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. |
Fishrock123
commented
Jun 24, 2016
@jasnell Seems like a better option for a userland module to do? |
71adf44 to
2c32c1fComparethefourtheye
commented
Jun 26, 2016
Okay, updated the PR to throw if the callback is not passed. PTAL. |
trevnorris
commented
Jun 27, 2016
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? |
2c32c1f to
bc57b2fComparethefourtheye
commented
Jun 28, 2016
@trevnorris I included a test now to check if the functions fail when callback is not passed. |
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');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?
There was a problem hiding this comment.
It's a little verbose, but should be as simple as:
if(typeofmode==='function'){callback=mode;mode=fs.F_OK;}if(typeofmode!=='number'||Number.isNaN(mode)){thrownewTypeError('mode must be a number');}if(typeofcallback!=='function'){thrownewTypeError('callback must be a function');}There was a problem hiding this comment.
If we are doing this, we should probably do the same for other methods as well.
There was a problem hiding this comment.
okay. I'd like that change, but let's keep that for another PR.
trevnorris
commented
Jun 28, 2016
I agree with @jasnell's opinion on grabbing the last argument. Other than that LGTM. |
trevnorris
commented
Jul 20, 2016
Still LGTM. With the note above that changing how arguments are parsed should go into another PR. |
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.
bc57b2f to
bff78cdComparethefourtheye
commented
Jul 21, 2016
Rebased. CI Run: https://ci.nodejs.org/job/node-test-pull-request/3366/ |
thefourtheye
commented
Jul 21, 2016
Landed in 9359de9. |
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>
MylesBorins
commented
Jul 22, 2016
oh hey all... looks like this broke /cc @nodejs/npm |
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>
othiym23
commented
Jul 27, 2016
Indeed, see npm/npm#13457 for further breakage that this causes in npm. What's the status on this? |
jasnell
commented
Jul 28, 2016
Status is that we will be reverting this specific change and taking a On Wednesday, July 27, 2016, Forrest L Norvell notifications@github.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: 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>
Checklist
Affected core subsystem(s)
fs
Description of change
The "fs" module has two functions called
maybeCallbackandmakeCallback, as of now.The
maybeCallbackcreates a default function to report errors, if theparameter 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 theparameter passed is
undefined, and if it is not a function object itwill throw an
Error.This patch removes the
maybeCallbackfunction and makes the callbackfunction argument mandatory for all the async versions.
cc @nodejs/collaborators