Skip to content

Commit 3213751

Browse files
authored
fix: should throw correct error when switching to a unexist version (#715)
* fix: should throw correct error when switching to a unexist version * chore: fix warning
1 parent 92cc44a commit 3213751

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

crates/loro-internal/src/loro.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,7 @@ impl LoroDoc {
13251325
}
13261326

13271327
let frontiers = if to_shrink_frontiers {
1328-
shrink_frontiers(frontiers, &oplog.dag)
1329-
.map_err(|_| LoroError::SwitchToVersionBeforeShallowRoot)?
1328+
shrink_frontiers(frontiers, &oplog.dag).map_err(LoroError::FrontiersNotFound)?
13301329
} else {
13311330
frontiers.clone()
13321331
};

crates/loro/tests/loro_rust_test.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,3 +3358,16 @@ fn test_from_shallow_snapshot() {
33583358
.insert("text".into(), LoroValue::String("Hello".into()));
33593359
assert_eq!(new_doc.get_deep_value(), LoroValue::Map(expected));
33603360
}
3361+
3362+
#[test]
3363+
fn test_checkout_to_unknown_version() {
3364+
let doc = LoroDoc::new();
3365+
doc.set_peer_id(1).unwrap();
3366+
doc.get_text("text").insert(0, "Hello").unwrap();
3367+
let result = doc.checkout(&Frontiers::from([ID::new(2, 2), ID::new(1, 1)]));
3368+
assert!(result.is_err());
3369+
assert!(matches!(
3370+
result.err().unwrap(),
3371+
LoroError::FrontiersNotFound(..)
3372+
));
3373+
}

0 commit comments

Comments
 (0)