| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
P.S. Don't run the tests yet, they'd probably need to be changed as this should probably be semver-major, as we're now throwing on values we previously accepted. Just take a look at the code and let me know what you think about it (for now). |
Sorry, something went wrong.
|
@nodejs/fs |
Sorry, something went wrong.
There was a problem hiding this comment.
Now that we are doing much stricter checks, isSafeInteger would be better I guess.
Sorry, something went wrong.
There was a problem hiding this comment.
@thefourtheye I think that does not apply here.
Sorry, something went wrong.
There was a problem hiding this comment.
@thefourtheye I think that does not too.
Sorry, something went wrong.
|
Is there a reason to make NaN be ERR_INVALID_ARG_TYPE instead of ERR_OUT_OF_RANGE? I would expect "Invalid type" if a type mismatches according to typeof or according to class / interface expectations, both don't apply here (typeof NaN === 'number'). From a practical point of view, NaN is most probably the result of an incorrect computation (e.g. Math.sqrt(-1)), and in such cases ERR_OUT_OF_RANGE might be easier to understand. |
Sorry, something went wrong.
There was a problem hiding this comment.
@thefourtheye I think that does not apply here.
Sorry, something went wrong.
|
@tniessen I think you misread the change. As far as I see it, your suggestion is already the case in this PR. |
Sorry, something went wrong.
|
@ryzokuken What's the reasoning behind rounding floats? To me, a floating point number implies the user is not passing what they intended to pass. Rather than rounding it (ie: magic), I personally would prefer it to throw. |
Sorry, something went wrong.
|
@ronkorving I had something similar in mind, but Anna convinced me otherwise and with good reason. A lot of people do a ton of math to get the values of start and end, and things might not go exactly as planned. Quoting @addaleax here:
For a better insight into our conversations and how we came to this final decision, read the thread at the reference PR (#19732). |
Sorry, something went wrong.
|
I haven't reviewed the code because I am a little busy these days. Would you like to write/quote the reason of using Math.round etc. in the code? I used to do that in my own projects to prevent good people from wasting creative mind on checking the code. |
Sorry, something went wrong.
|
I am wondering if (Infinity,Infinity) breaks ReadStream...... |
Sorry, something went wrong.
|
@anliting No idea. We could test for that, though. I'll be adding/updating unit tests for ReadStream today. |
Sorry, something went wrong.
|
I mean, you program seems to allow passing Infinity for start, but I am not sure if the other parts will break on this.start==Infinity. |
Sorry, something went wrong.
|
Added new tests and updated existing ones, take a look when you can. The tests might look a little too much, but better be safe than be sorry, I guess. |
Sorry, something went wrong.
|
I tried running tests locally, and none of my new tests seemed to fail (which sounds good), but a seemingly related failed. Could someone help me debug it? === release test-fs-read-stream ===
Path: parallel/test-fs-read-stream
events.js:167
throw er; // Unhandled 'error' event
^
Error: ESPIPE: invalid seek, read
Emitted 'error' event at:
at fs.read (fs.js:2130:12)
at FSReqWrap.wrapper [as oncomplete] (fs.js:569:17)
Command: out/Release/node /Users/ryzokuken/Code/nodejs/node/test/parallel/test-fs-read-stream.js
|
Sorry, something went wrong.
There was a problem hiding this comment.
I’m mostly sure this is the cause of the test failure – start: 0 and start: undefined aren’t equivalent, because the former means that the stream will use reads with an offset parameter (which doesn’t work on all types of files). If start: undefined was passed, this value should be undefined, too.
Sorry, something went wrong.
There was a problem hiding this comment.
Alright, let me just remove the condition then.
Sorry, something went wrong.
|
@addaleax better now? Running tests locally. Please run CI whenever you can. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM, assuming the start-related checks are grouped in a block that ignores start === undefined (or something equivalent to that)
Sorry, something went wrong.
There was a problem hiding this comment.
I think you want to allow undefined explicitly here and for the other checks as well?
(The if (this.start !== undefined) { block from the original variant of this code seems like a pretty reasonable idea, tbh…)
Sorry, something went wrong.
There was a problem hiding this comment.
Okay. So, should I enclose all the type-checking code within that statement?
Sorry, something went wrong.
There was a problem hiding this comment.
@ryzokuken All that’s related to start, yes. end is another story, and my original TODO was more or less about keeping the end checks out of such a block :)
Sorry, something went wrong.
There was a problem hiding this comment.
Exactly. That's why I wanted to keep the checks separate, so they worked either way.
I've enclosed all this code into the if block, which should work if end does not need to be transformed or checked at all if start is undefined. That probably isn't the case, is it?
P.S. How should I handle end if start is undefined? Similar to how it was handled earlier?
Edit: Sorry, misunderstood you. Working on it. Hopefully, it will work now.
Sorry, something went wrong.
|
Umm, okay. So a couple of other ReadStream related tests throw now. The arguments passed don't qualify by the newer standards, I guess. |
Sorry, something went wrong.
|
@addaleax How about this instead? |
Sorry, something went wrong.
There was a problem hiding this comment.
I guess we would want to do the type checking for end before we get to this block? Otherwise end: undefined would get converted to Math.round(undefined) here, which is NaN… if I read the code correctly?
Sorry, something went wrong.
There was a problem hiding this comment.
Holy moly. I missed this one and got a few failing tests for NaN. Stupid me, I guess. Thanks for pointing this out.
Sorry, something went wrong.
There was a problem hiding this comment.
I’m a bit confused by the comment here – we do round to the nearest integer, right?
Sorry, something went wrong.
There was a problem hiding this comment.
We do. But because we've already thrown on negatives, we're only left with positive fractions, which will either round to zero or positive integers (whole numbers). I used this term because it's more precise (factually).
If you want, I could remove it and just say that we're rounding to the nearest Integer.
Sorry, something went wrong.
|
@addaleax hopefully, it should work perfectly now. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM! :)
Sorry, something went wrong.
There was a problem hiding this comment.
I think this works fine, but as far as I can tell that is because end: undefined gets coerced to NaN here (which makes this condition always false), and that the fact that we later round end does not affect this comparison
Maybe it would be a bit more obvious that this works if we swap type checking for end and start?
Sorry, something went wrong.
There was a problem hiding this comment.
Umm, I couldn't understand what you meant. Should I move the end block to check first and then check for start?
end isn't being coerced to NaN before this anymore, but end does get rounded off later on in the code.
Sorry, something went wrong.
There was a problem hiding this comment.
@ryzokuken What I meant was, end is being coerced to NaN in this comparison if it was passed in as undefined, because we haven’t yet gotten to the part where it’s converted to Infinity.
Sorry, something went wrong.
There was a problem hiding this comment.
Oh. so, should I move the block that handles this.end === undefined first and move to a similar type-check below?
Let me make it and demonstrate.
Sorry, something went wrong.
|
Okay, looks like the tests passed for me this time around, so that's probably a good sign. |
Sorry, something went wrong.
|
@addaleax it does feel much better now, doesn't it? Definitely more consistent (start !== undefined vs end !== undefined). |
Sorry, something went wrong.
|
@BridgeAR you're right, only two files had an hardcoded check for that test and I had also updated one. Running tests in a jiffy. |
Sorry, something went wrong.
Sorry, something went wrong.
|
Wait, the lint errors are still here. |
Sorry, something went wrong.
|
Broke down the three lines that were failing on us, all tests should pass now. Waiting for tests to pass locally first this time. |
Sorry, something went wrong.
|
Okay, tests pass. |
Sorry, something went wrong.
|
Seems to be an unrelated error with https://ci.nodejs.org/job/node-test-binary-windows/17146/, rerunning. |
Sorry, something went wrong.
|
Binary Windows Test: https://ci.nodejs.org/job/node-test-binary-windows/17161/ |
Sorry, something went wrong.
Sorry, something went wrong.
|
Another Java error: https://ci.nodejs.org/job/node-test-commit-freebsd/17632/nodes=freebsd10-64/console Aren't we having too many of these lately? |
Sorry, something went wrong.
|
Optimistic CI run: https://ci.nodejs.org/job/node-test-pull-request/14780/ |
Sorry, something went wrong.
Sorry, something went wrong.
|
@ryzokuken the CI does not have to be "green green". All tests related to this PR pass and what you encounter otherwise are flakes. Some are infrastructure issues and some times some tests are not written well enough. That is normal but it does not mean this PR needs any more work. It can land as it is. |
Sorry, something went wrong.
|
@BridgeAR so, should I land it? Any CITGM or benchmark runs required? |
Sorry, something went wrong.
|
@ryzokuken running CITGM for semver-majors is always best to detect failures early that have to be fixed. I doubt that it is going to be an issue in this case but here they are nevertheless: CITGM https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1404/ When they come out "green" (there will be quite a few failures and therefore it is easier to compare the output of those two. If they diverge, check if it has something to do with this PR) you should feel free to land the PR. |
Sorry, something went wrong.
|
@BridgeAR sounds great! Thanks. |
Sorry, something went wrong.
|
@BridgeAR not the exact same, but mine had a few less failures? (59 vs 66). Also, a single less skipped test. I hope it's okay to land? |
Sorry, something went wrong.
Improve handling of erratic arguments in fs.ReadStream Refs: #19732 PR-URL: #19898 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
| Back | FazBrowse Home | New Git URL |
Improve handling of erratic arguments in fs.ReadStream
Refs: #19732
For the uninitiated, a summary of what I'm planning to change:
Checklist
cc @addaleax @anliting @nodejs/fs