Open
Description
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:
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:
let doc = Doc::new();
// do some complex operations
// encode to binary, no error message, only panic when something goes wrong
let data = doc.transact().state_vector().encode_v1();
After:
let doc = Doc::new();
// do some complex operations
// encode to binary, catch error through `Result`
let data = doc.transact().state_vector().encode_v1()?;
// or
match doc.transact().state_vector().encode_v1() {
Ok(data) => {
// on success
},
Err(e) => {
// on error
}
}
Metadata
Metadata
Assignees
Labels
No labels