Skip to content

Commit

Permalink
fix: find last_delete_op can return none
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Aug 27, 2024
1 parent efc50fa commit 227d1aa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/loro-internal/src/loro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,10 @@ impl LoroDoc {
.id_to_idx(&pos.container)
.ok_or(CannotFindRelativePosition::ContainerDeleted)?;
// We know where the target id is when we trace back to the delete_op_id.
let delete_op_id = find_last_delete_op(&oplog, id, idx).unwrap();
let Some(delete_op_id) = find_last_delete_op(&oplog, id, idx) else {
tracing::error!("Cannot find id {}", id);
return Err(CannotFindRelativePosition::IdNotFound);
};
let mut diff_calc = DiffCalculator::new();
let before_frontiers: Frontiers = oplog.dag.find_deps_of_id(delete_op_id);
let before = &oplog.dag.frontiers_to_vv(&before_frontiers).unwrap();
Expand Down Expand Up @@ -1341,7 +1344,7 @@ impl LoroDoc {
}

fn find_last_delete_op(oplog: &OpLog, id: ID, idx: ContainerIdx) -> Option<ID> {
let start_vv = oplog.dag.frontiers_to_vv(&id.into()).unwrap();
let start_vv = oplog.dag.frontiers_to_vv(&id.into())?;
for change in oplog.iter_changes_causally_rev(&start_vv, &oplog.dag.vv) {
for op in change.ops.iter().rev() {
if op.container != idx {
Expand Down

0 comments on commit 227d1aa

Please sign in to comment.