-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Offset must be >= 0 && <= 0 Out of range 0 :-) #21193
Comments
There should be an error for this because the buffer is empty and can't be written, although the error message does look pretty funny and this error (bufferLength === 0) should be special cased. If anyone is interested, the enhancement should be added in Lines 293 to 307 in 6dbd6f6
(Not sure if this count as a good first issue so I'll just add help wanted for new contributors) |
Aha, so it was referring to my uint8array :-). Indeed changing constructor to make 10 bytes solved it.
However the message text is still funny, maybe renaming offset to "target_offset" or something might make it a bit easier for n00bs like me? :-) |
Thank you by the way! |
@amno1 I think the better error should probably just be I could fix this myself if no new contributor want to pick this up. The internal error system is documented here: https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md |
Just put a bit more clear message in error message and probably in documentation as well, what "offset" means. I was looking at docs, since I am really a C/C++ programmer, and wasn't really clear why there was both position and offset. The error message didn't help much :-). This is what docs says:
Just make it a bit more clear in which ever way you prefer. |
The convention of the fs docs is: the actual explanation in under the async version of that API. In this case, Probably deserves another good first issue to make it more explicit, something like |
As mentioned by @joyeecheung, this is just a matter of improving the current error messages in Lines 293 to 307 in 6dbd6f6
ERR_INVALID_ARG_VALUE or a modified version of ERR_INVALID_BUFFER_SIZE maybe. PRs welcome, labelling as good-first-issue .
|
I want to give this a try. Will report back in two days. |
@AdityaSrivast sure thing! Feel free to reach out if you face any issues setting everything up. |
@ryzokuken Is there any way to test this error and know that I have fixed it? |
@AdityaSrivast as mentioned by @amno1, the test case for this is: let string = new Uint8Array();
let num = fs.readSync(keyfile, string, 0, 10, 0); this should trigger the error, just make sure to test it works and changed and in the end, add a test that checks if the error is the correct one with |
@ryzokuken Where is this code(test case) to be typed? |
@AdityaSrivast Make a test script, or try running it in the REPL. |
P.S. You'd also need to set something to the |
You don't need to hack the source. Just add to documentation what offset variable is referring to. That is probably the easiest thing to do. Otherwise, the code I was using:
"Testcodes" is just a textfile with strings of certain length, in this case lentgh was 10. Everything was just a small test to see how node api compares to C api since I am not JS developer.
Run it with |
@amno1 from the given code I am not getting OUT_OF_RANGE error. Instead, the error message which I am getting is: Error: Offset is out of bounds I am using node -v8.11.2. However I also want to test against current repository. Can anyone help me out ? It is unclear to me (i)where to type wrong code and (ii)how to record the henceforth coming error (while testing with 'repository'). Please correct me if I have understood wrong anywhere. |
Obviously from my very first post I am using node 10.4.0, so you should update your node if you wish to have exact same message :-).
|
Oh! I missed that out. @amno1 Thanks a lot for correcting. I have upgraded my nodejs. |
should this just have a check |
Just emit more sensible error message and mention in docs what offset parameter refers to. |
@ryzokuken Is there any way I can run the code using current node repository and record the error message? I have used assert.expectsError() in test/parallel/test-internal-errors.js but I don't know how to record the message from the error in the code(test case). |
@AdityaSrivast have you checked the contributing and running tests instructions? These might help you, Running these will run the tests against the current code you have in your repository:
|
@jrasanen I have already tried it. It takes more than 1 hour and without any outcome, which is very long for running few lines of code |
@AdityaSrivast hm, you can update a single test only
And if you change node's source, you can just run |
Hey, I have made a commit which does not follow 72 column rule. What to do? Should I remove it? Also this is my first commit so it would be great if someone helps me out how to do it smoothly. :) |
Ok I worked it out. Thanks anyways 😃 |
@AdityaSrivast you can amend the commit message. |
ERR_INVALID_ARG_VALUE is an error for wrong arguments given to the function. But calling a function without argument should also generate a sensible error message. For no argument case, parameter 'value' should be passed with zero value and the error message is generated. In readSync(fd, buffer, offset, length, position), triggers validateOffsetLengthRead() in lib/internal/fs/utils.js for validation. When buffer is empty, a weird message is generated "The value of offset is out of range.It must be >= 0 && <= 0. Received 0". There should be a special case when buffer is empty or bufferLength is zero, which should trigger ERR_INVALID_ARG_VALUE error. Fixes: nodejs#21193
ERR_INVALID_ARG_VALUE is an error for wrong arguments given to the function. But calling a function without argument should also generate a sensible error message. For no argument case, parameter 'value' should be passed with zero value and the error message is generated. In readSync(fd, buffer, offset, length, position), triggers validateOffsetLengthRead() in lib/internal/fs/utils.js for validation. When buffer is empty, a weird message is generated "The value of offset is out of range.It must be >= 0 && <= 0. Received 0". There should be a special case when buffer is empty or bufferLength is zero, which should trigger ERR_INVALID_ARG_VALUE error. Fixes: nodejs#21193
In validateOffsetLengthRead(), an error message is generated if offset or length are out of range. There should also be an error message if buffer is empty, in which case it cannot write data in it. Generally this validateOffsetLengthRead() is triggered with fs.readSync(fd, buffer, offset, length, position), where if buffer is empty, the case for zero bufferLength is triggered and the corresponding message is thrown. Fixes: nodejs#21193
In validateOffsetLengthRead(), an error message is generated if offset or length are out of range. But there should also be an error message if buffer is empty, when no data can be written on it. Generally, validateOffsetLengthRead() is triggered with fs.readSync(fd, buffer, offset, length, position), where if 'buffer' is empty, the case for zero bufferLength should be triggered and the error message for empty buffer should be thrown. Fixes: nodejs#21193
While using read() or readSync() function, it should be verified that the arguments of the function are in proper range and hold legitimate values, for a successful read process. For this validateOffsetLengthRead() function is called, which gives an error message for offset and length passed by the user, if not in order. But there should also be an error when an empty buffer is passed as argument, when it cannot be written over. The empty buffer case should be checked before calling validateOffsetLengthRead() and ERR_INVALID_ARG_VALUE should be thrown corresponding to the empty buffer argument in read and readSync function. Fixes: nodejs#21193
While using read() or readSync() function, it should be verified that the arguments of the function are in proper range and hold legitimate values, for a successful read process. For this validateOffsetLengthRead() function is called, which gives an error message for offset and length passed by the user, if not in order. But there should also be an error when an empty buffer is passed as argument, when it cannot be written over. The empty buffer case should be checked before calling validateOffsetLengthRead() and ERR_INVALID_ARG_VALUE should be thrown corresponding to the empty buffer argument in read and readSync function. Fixes: nodejs#21193
I’m a bit confused … I updated the |
It should have. I suppose GitHub missed the event. |
@targos Hi, I just wanted to know if we have to add our names to contributors' list somewhere to become an official contributor, please? |
I am trying to read a file and I am getting error when trying to read at beginning. As seen above, it says offset must be >= 0 and <= 0. It is very interesting error message i must say. Anyway I am using offset 0 and I get that error :-). I am just trying to read 10 bytes into an Uint8Array. Here is the call
The text was updated successfully, but these errors were encountered: