-
Notifications
You must be signed in to change notification settings - Fork 71
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
api proposal: add Result
return value to Encode
#288
Comments
Tbh. if I remember correctly, the panic that you've quoted should be unreachable - all integrated blocks always have parent set, otherwise it's a bug. We pretty much did what we can in order to catch error-prone data. There's also another reason for that - if you passed data that cannot be serialised into Where errors could be useful in serialisation process is when the |
In my practice, I only receive updates generated by Yjs and apply them to Doc instances in memory. In some unknown scene(It usually happens after maintaining the connection in a client for more than 1 day. At present, some of our users are using edge or arc. They allow users to keep a tag active for a long time. At this time, the update generated by yjs will be sent to the server from time to time.), updates generated by Yjs can be successfully applied to Doc instances, but encoding them into binary fails - the usual failure is caused by "Couldn't get item's parent". It sounds like what we should do more is to see if |
The other benefit of making |
Motivation
When encoding crdt items into binary, unexpected data may be encountered. At this time, yrs will interrupt the execution process through
panic!
like this:y-crdt/yrs/src/block.rs
Line 882 in f5f7792
The panic will cause the execution thread to crash, which makes the developer need to isolate the relevant calls of yrs through
catch_unwind
or other means in actual development.Rust provides
Result
abstraction, which allows us to deal with errors more gently.Currently, the
Decode
trait already supports returning Result, so developers can safely handle decoding errors when encountering erroneous data:y-crdt/yrs/src/updates/decoder.rs
Lines 10 to 12 in f5f7792
Use Case
Before:
After:
The text was updated successfully, but these errors were encountered: