File tree 2 files changed +10
-1
lines changed
2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 1
1
use pyo3:: prelude:: * ;
2
+ use pyo3:: exceptions:: PyValueError ;
2
3
use pyo3:: types:: { PyBytes , PyDict , PyLong , PyList } ;
3
4
use yrs:: {
4
5
Doc as _Doc,
@@ -87,7 +88,8 @@ impl Doc {
87
88
fn get_update ( & mut self , state : & PyBytes ) -> PyResult < PyObject > {
88
89
let txn = self . doc . transact_mut ( ) ;
89
90
let state: & [ u8 ] = FromPyObject :: extract ( state) ?;
90
- let update = txn. encode_diff_v1 ( & StateVector :: decode_v1 ( & state) . unwrap ( ) ) ;
91
+ let Ok ( state_vector) = StateVector :: decode_v1 ( & state) else { return Err ( PyValueError :: new_err ( "Cannot decode state" ) ) } ;
92
+ let update = txn. encode_diff_v1 ( & state_vector) ;
91
93
drop ( txn) ;
92
94
let bytes: PyObject = Python :: with_gil ( |py| PyBytes :: new ( py, & update) . into ( ) ) ;
93
95
Ok ( bytes)
Original file line number Diff line number Diff line change @@ -203,3 +203,10 @@ def test_not_empty_update():
203
203
events .clear ()
204
204
del text [5 ]
205
205
assert events
206
+
207
+
208
+ def test_get_update_exception ():
209
+ doc = Doc ()
210
+ with pytest .raises (ValueError ) as excinfo :
211
+ doc .get_update (b"\x12 " )
212
+ assert str (excinfo .value ) == "Cannot decode state"
You can’t perform that action at this time.
0 commit comments