fs: change default value of position in read and readSync#37101
fs: change default value of position in read and readSync#37101RaisinTen wants to merge 4 commits intonodejs:masterfrom
Conversation
Originally posted by @Trott in #36190 (comment) cc @Trott Since you mentioned this idea. |
|
|
||
| // Read only five bytes, so that the position moves to five. | ||
| fs.read(fd, buf, 0, 5, null, common.mustSucceed((bytes) => { | ||
| fs.read(fd, buf, 0, 5, -1, common.mustSucceed((bytes) => { |
There was a problem hiding this comment.
Can you keep the null test please? We want null to still works – or mark the PR as semver-major.
EDIT: I've added the semver-major label, you can remove it if you change the code to rollback the behaviour for null.
There was a problem hiding this comment.
I think this should be semver-major as it is supposed to reject a null value for position which was accepted previously. Thanks for adding the label.
There was a problem hiding this comment.
On a second thought, we should probably deprecate it before removing it.
There was a problem hiding this comment.
I added the deprecation warning, test and mentioned the PR link in the YAML. PTAL. 👀
|
|
||
| if (position == null) | ||
| position = -1; | ||
|
|
There was a problem hiding this comment.
We should actually keep this with if (position === null) given that the default assignment will not work when position is explicitly passed as null.
There was a problem hiding this comment.
@jasnell Note this was intentional, see #37101 (comment) above.
There was a problem hiding this comment.
@jasnell added the check back in along with a deprecation warning.
| validateOffsetLengthRead(offset, length, buffer.byteLength); | ||
|
|
||
| if (position == null) | ||
| position = -1; |
There was a problem hiding this comment.
Likewise here, this check should be kept
70f5ff4 to
5145747
Compare
|
Usually we tend to avoid going Runtime deprecation without a doc-only deprecation first – unless there's a security risk we are trying to mitigate, but that's not the case here. You also need to add the deprecation description on Refs: https://github.com/nodejs/node/blob/master/doc/guides/collaborator-guide.md#deprecations |
|
Okay. Should I open a separate PR to make it a doc-only deprecation first? After that lands, we can work on this PR to add the runtime warning. Finally, a PR can be raised to turn it into an EOL deprecation. |
|
The proposed default value for |
|
@wa-Nadoo |
|
What's the reason for deprecating |
|
I intended to deprecate |
|
need rebase to resolve git-conflicts |
Since the docs mention that `position` in `read` and `readSync` should be an `integer` or a `bigint`, the functions should rather accept what is actually fed into `read`, i.e., `-1` instead of any nullish value.
6a815f7 to
446bdb6
Compare
|
@PoojaDurgad Thanks for mentioning, I rebased it. |
@aduh95 Finally opened the PR to doc-only deprecate this - #38043. :) |
Note that I appreciate the time you spend working in this, but I think Rich has a point. Also if #37948 lands, I'd be -1 to land this.
|
@aduh95 Thank you for the review. Along with deprecating nullish values for Should documenting this be okay if #37948 lands? Even if we document this, wouldn't it feel weird why the default value for |
|
Changing a default is not necessarily semver-major, as long as it is not a breaking change.
IMHO changing the value in the docs makes sense, whether or not #37948 lands. I don't have a strong opinion regarding deprecation status of nullish values, I tend to be on board for calling it legacy and keep it as is though. |
|
@aduh95 I noticed the validation logic is similar in |
|
I don't really have an opinion, I guess it would make sense to change all default values documented to |
|
I don't think this is worth the breakage anymore. |
Since the docs mention that
positioninreadandreadSyncshouldbe an
integeror abigint, the functions should rather accept whatis actually fed into
read, i.e.,-1instead of any nullish value.