lib: deprecate fd usage for fs.truncate and fs.truncateSync#15990
lib: deprecate fd usage for fs.truncate and fs.truncateSync#15990r1cebank wants to merge 2 commits intonodejs:masterfrom r1cebank:deprecate-fd-usage-fs-truncate
Conversation
BridgeAR
left a comment
There was a problem hiding this comment.
We need a note in the deprecations.md about the new deprecation.
lib/fs.js
Outdated
There was a problem hiding this comment.
Nit - this should be indented with two more spaces while landing. The same applies to the other deprecation messages.
There was a problem hiding this comment.
The message itself could also be improved by not saying In the future ... but just Please use ... instead.
There was a problem hiding this comment.
I agree with switching to Please use .... Additionally, the occurrences of "with file descriptor" should likely be "with a file descriptor"
doc/api/deprecations.md
Outdated
There was a problem hiding this comment.
"if you need" is redundant IMO. Also there should be a period at the end of the sentence.
doc/api/deprecations.md
Outdated
There was a problem hiding this comment.
I think we're supposed to be using DEP00XX when authoring these deprecations. Then, when the PR is landed, the committer can replace it with a number.
lib/fs.js
Outdated
There was a problem hiding this comment.
Please use util.deprecate() for runtime deprecations. See how it's done here.
There was a problem hiding this comment.
I asked one of the mentor during the event, and looks like for this case since we are deprecating a particular usage, we cannot use util.deprecate().
There was a problem hiding this comment.
Indeed. But we still need to make sure this warning is only emitted once and that it respects --no-deprecation. See how it's done with Buffer here (although that's a pending deprecation for now, so make sure to use process.noDeprecation instead of pendingDeprecation)
There was a problem hiding this comment.
Oh I see what you mean, thank you for sharing the resources, I will make changes according to what you said.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Minor nit: this line is > 80 chars and will need to be wrapped before landing.
lib/fs.js
Outdated
There was a problem hiding this comment.
This part is unnecessary. The emitWarning function will handle the noDeprecation configuration property internally.
There was a problem hiding this comment.
This was suggested by one of the reviewers, I am just here to learn how nodejs works internally. If you think emitWarning is sufficient, i can make the change.
|
Ping @nodejs/tsc |
|
Can someone give me a clear idea how this should be fixed? I feel all this back and forth commenting just made me more confused. |
|
@r1cebank ... first of all, thank you very much for the contribution, it really is quite appreciated. My apologies if the reviews were not clear. Essentially there are a couple of things here that should be reworked slightly. Namely, I would change your code here: const doFlaggedDeprecation = noDeprecation ?
function() {} : showFlaggedDeprecation;
function showFlaggedDeprecation() {
process.emitWarning(
'Using fs.truncate with a file descriptor is deprecated. Please use ' +
'fs.ftruncate with a file descriptor instead.',
'DeprecationWarning', 'DEP00XX');
}To the following: let truncateWarn = true;
function doFlaggedDeprecation() {
if (!truncateWarn) {
process.emitWarning(
'Using fs.truncate with a file descriptor is deprecated. Please use ' +
'fs.ftruncate with a file descriptor instead.',
'DeprecationWarning', 'DEP00XX');
truncateWarn = false;
}
}There are two reasons:
|
|
Thank you @jasnell for your wonderful explanation. I think I was little confused with the emit error only once part. Thanks for the code sample, this really helps with my understanding of Node.js. I will make these changes as soon as possible. |
|
I made the changes @jasnell I hope this addressed all of your concerns. |
lib/fs.js
Outdated
There was a problem hiding this comment.
Just a suggestion, but I’d include truncate in the function name here because it’s specific to fs.truncate(Sync)
There was a problem hiding this comment.
Very good suggestion, I will keep this in mind in my future works. Thanks
trevnorris
left a comment
There was a problem hiding this comment.
missed a space in the doc change and the git message in the second commit is too long (max 50 chars). Thanks for the patch.
doc/api/deprecations.md
Outdated
There was a problem hiding this comment.
missed a space "descriptor has"
|
I have fixed both commit messages + missing space, thanks for the suggestion. |
|
Anyone know if I can get read permission for jenkins? I cannot check the status of the build atm. |
|
Failure in CI is unrelated. |
PR-URL: #15990 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
|
Landed in c885ea7 |
PR-URL: nodejs/node#15990 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Address issue #15753
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)