fs: throw on invalid callbacks for async functions#12562
fs: throw on invalid callbacks for async functions#12562thefourtheye wants to merge 1 commit intonodejs:masterfrom
Conversation
940a81a to
6e6aa0a
Compare
lib/fs.js
Outdated
There was a problem hiding this comment.
This function's implementation should be changed too. In fact, I'd rather just get rid of rethrow() altogether and just copy the throw ... where needed as I don't see the value in having a function that all it does is throw an exception (+ it avoids a potential function call).
There was a problem hiding this comment.
Might be worth benchmarking. I thought using throw directly could de-opt a function? I had some fairly mysterious regressions in performance when doing some tiny refactors like this with an old experiment.
There was a problem hiding this comment.
@sam-github Not throwing, but try-catch/try-finally used to. However I think with the V8 in node v7.x, functions containing try-catch/try-finally are optimizable, but are still not inlineable (not sure if the inlineability limit was with Crankshaft or TurboFan or both though).
There was a problem hiding this comment.
Definite +1 to getting rid of rethrow() if we can
There was a problem hiding this comment.
I refactored it a little bit to get rid of rethrow. PTAL.
|
This would require a documentation change both |
lib/fs.js
Outdated
There was a problem hiding this comment.
Wherever this error ends up being thrown, please include a comment that indicates that this previously was a deprecation with ID code DEP0013
There was a problem hiding this comment.
Since this is semver-major already, please migrate the error to use the new internal/errors.js API.
lib/fs.js
Outdated
There was a problem hiding this comment.
Definite +1 to getting rid of rethrow() if we can
6e6aa0a to
2ffd589
Compare
test/parallel/test-fs-access.js
Outdated
There was a problem hiding this comment.
These can be changed to use common.expectsError({code: 'ERR_INVALID_CALLBACK'})
test/parallel/test-fs-chmod.js
Outdated
There was a problem hiding this comment.
alternatively this could be fs.close(fd, common.noop), but this works also.
There was a problem hiding this comment.
const cbTypeError = common.expectsError({code: 'ERR_INVALID_CALLBACK'});There was a problem hiding this comment.
ditto ... I'll stop pointing these out.
7a75ee6 to
f4255cc
Compare
|
Thanks @jasnell :-) Updated the PR as per your suggestions. |
lib/fs.js
Outdated
There was a problem hiding this comment.
Can the conditionals' bodies be placed on separate lines please?
|
FWIW I still prefer to see the check/throw copied where needed instead of making |
f4255cc to
c9c99e5
Compare
|
@mscdex Addressed your comments now. PTAL. |
doc/api/fs.md
Outdated
There was a problem hiding this comment.
I would still prefer to stick with REPLACEME for the versions themselves (unless you’re reasonably sure that this doesn’t need to be fixed up again 😄 )
There was a problem hiding this comment.
Sure, updated to REPLACEME now. PTAL.
c9c99e5 to
97c570b
Compare
If an asynchronous function is passed no callback function, there is no way to return the result. This patch throws an error if the callback passed is not valid or none passed at all.
97c570b to
2096f8b
Compare
|
CI is green. I'll land this tomorrow, if there are no objections. |
If an asynchronous function is passed no callback function, there is no way to return the result. This patch throws an error if the callback passed is not valid or none passed at all. PR-URL: #12562 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This reverts 4cb5f3d Based on community feedback I think we should consider reverting this change. We should explore how this could be solved via linting rules. Refs: #12562 PR-URL: #12976 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This reverts 4cb5f3d Based on community feedback I think we should consider reverting this change. We should explore how this could be solved via linting rules. Refs: #12562 PR-URL: #12976 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
|
Not providing callback to async function, is similar to not providing an error handler to event listener. In latter case node.js throws since very early days, and it seems as great pattern that works for most developers. So taking this in (not just as a depreaction warning), will just make error handling in Node.js more consistent (and for 100% coverage we also need #12010 ) |
This reverts commit 8250bfd. PR-URL: nodejs#18668 Refs: nodejs#12562 Refs: nodejs#12976 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
The callback should run in the global scope and not in the FSReqWrap context. PR-URL: nodejs#18668 Refs: nodejs#12562 Refs: nodejs#12976 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
* v10.0.0 -> Node.js 10.0.0 * Parenthetical with URL rather than "PR" as a lot of people may not know what "PR" stands for but they will know what a URL is. Plus not hiding the URL means the text is more copy/paste-able. In this particular case, "PR 12562" is not more useful or informative than nodejs#12562 so just use the URL.
* v10.0.0 -> Node.js 10.0.0 * Parenthetical with URL rather than "PR" as a lot of people may not know what "PR" stands for but they will know what a URL is. Plus not hiding the URL means the text is more copy/paste-able. In this particular case, "PR 12562" is not more useful or informative than nodejs#12562 so just use the URL. PR-URL: nodejs#20519 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This reverts commit 8250bfd. PR-URL: nodejs#18668 Refs: nodejs#12562 Refs: nodejs#12976 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
The callback should run in the global scope and not in the FSReqWrap context. PR-URL: nodejs#18668 Refs: nodejs#12562 Refs: nodejs#12976 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
* v10.0.0 -> Node.js 10.0.0 * Parenthetical with URL rather than "PR" as a lot of people may not know what "PR" stands for but they will know what a URL is. Plus not hiding the URL means the text is more copy/paste-able. In this particular case, "PR 12562" is not more useful or informative than #12562 so just use the URL. PR-URL: #20519 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
* v10.0.0 -> Node.js 10.0.0 * Parenthetical with URL rather than "PR" as a lot of people may not know what "PR" stands for but they will know what a URL is. Plus not hiding the URL means the text is more copy/paste-able. In this particular case, "PR 12562" is not more useful or informative than #12562 so just use the URL. PR-URL: #20519 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
* v10.0.0 -> Node.js 10.0.0 * Parenthetical with URL rather than "PR" as a lot of people may not know what "PR" stands for but they will know what a URL is. Plus not hiding the URL means the text is more copy/paste-able. In this particular case, "PR 12562" is not more useful or informative than #12562 so just use the URL. PR-URL: #20519 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
As per this nodejs/node#12562 node PR callback in async fs functions is no longer optional. This commit fixes remaining usages in impress.
As per this nodejs/node#12562 node PR callback in async fs functions is no longer optional. This commit fixes remaining usages in impress. Refs: #852 PR-URL: #856
Now mandatory in NodeJS 10. See nodejs/node#12562
If an asynchronous function is passed no callback function, there is no
way to return the result. This patch throws an error if the callback
passed is not valid or none passed at all.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
fs
@nodejs/ctc