-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: change default value of position in read and readSync #37101
fs: change default value of position in read and readSync #37101
Conversation
Originally posted by @Trott in #36190 (comment) cc @Trott Since you mentioned this idea. |
@@ -79,7 +79,7 @@ function tempFdSync(callback) { | |||
const buf = Buffer.alloc(5); | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, we should probably deprecate it before removing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the deprecation warning, test and mentioned the PR link in the YAML. PTAL. 👀
@@ -546,9 +546,6 @@ function read(fd, buffer, offset, length, position, callback) { | |||
|
|||
validateOffsetLengthRead(offset, length, buffer.byteLength); | |||
|
|||
if (position == null) | |||
position = -1; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell Note this was intentional, see #37101 (comment) above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell added the check back in along with a deprecation warning.
@@ -612,9 +613,6 @@ function readSync(fd, buffer, offset, length, position) { | |||
|
|||
validateOffsetLengthRead(offset, length, buffer.byteLength); | |||
|
|||
if (position == null) | |||
position = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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
position
inread
andreadSync
shouldbe an
integer
or abigint
, the functions should rather accept whatis actually fed into
read
, i.e.,-1
instead of any nullish value.