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
[RangeError] use
missing size parameter
#11
Comments
Yes, the package is outdated, I haven't published to NPM yet. I need to make sure everything is right before the push. Although, it is strange that you are getting this error. The array buffer should grow by itself upon encountering this error. I will investigate this error tomorrow if I have time and publish it. |
I was able to reproduce this bug with the following code: import * as sd from 'sirdez';
const contextByteLength = 4096;
const headByteLength = 2;
const data = new Uint8Array(contextByteLength - headByteLength + 1);
const serdes = sd.use(sd.bytes(sd.uint16));
serdes.toBytes(data); This code throws exception The context size is the default one used in code - 4096 bytes, 2 bytes are taken for head, so we have only 4094 bytes left. The Next, the exception is caught here. When serializing data, there might happen 2 types of errors: error caused by small size of the buffer, and some user error unrelated to the buffer. If error is caused by the buffer size, we need to ignore it and grow the buffer. If error is a user error, we need to re-throw it. The code assumes that if So, maybe we should replace if (!(error instanceof RangeError)) throw error; That is, assume that every |
Another solution that will make use of the if guard I think adding both the limit check and the |
I hope this issue only concerns |
I made some changes and some tests reflecting the suggestion above, hopefully, it is fine. #11 (comment) |
It seems like in Maybe add warning for Or set rule level to |
Using this serde declaration:
I get the following error:
Looking at the source code I should be able to create a context with a larger size than the default value. For that I would expect to call
use
second parameter, size with a size.However, the signature available for
sd.use
in my current project is this:I was expecting to have something like this:
What am I doing wrong?
The text was updated successfully, but these errors were encountered: