Skip to content

Commit 0a3fe93

Browse files
committed
refactor(event cache): don't panic when loading a linked chunk's latest event fails
This can happen because of an OS-level error, so let's try to handle it in a slightly cleaner way. At the moment, it will bubble up and only be logged, but we might try to find a better way to handle this at the top-level.
1 parent 37e07ea commit 0a3fe93

File tree

1 file changed

+17
-4
lines changed
  • crates/matrix-sdk/src/event_cache/room

1 file changed

+17
-4
lines changed

crates/matrix-sdk/src/event_cache/room/mod.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ mod private {
720720
"error when loading a linked chunk's metadata from the store: {err}"
721721
);
722722

723-
// Clear storage for this room.
723+
// Try to clear storage for this room.
724724
store_lock
725725
.handle_linked_chunk_updates(linked_chunk_id, vec![Update::Clear])
726726
.await?;
@@ -730,15 +730,28 @@ mod private {
730730
}
731731
};
732732

733-
let linked_chunk = store_lock
733+
let linked_chunk = match store_lock
734734
.load_last_chunk(linked_chunk_id)
735735
.await
736736
.map_err(EventCacheError::from)
737737
.and_then(|(last_chunk, chunk_identifier_generator)| {
738738
lazy_loader::from_last_chunk(last_chunk, chunk_identifier_generator)
739739
.map_err(EventCacheError::from)
740-
})
741-
.expect("fully loading the linked chunk just worked, so loading it partially should also work");
740+
}) {
741+
Ok(linked_chunk) => linked_chunk,
742+
Err(err) => {
743+
error!(
744+
"error when loading a linked chunk's latest chunk from the store: {err}"
745+
);
746+
747+
// Try to clear storage for this room.
748+
store_lock
749+
.handle_linked_chunk_updates(linked_chunk_id, vec![Update::Clear])
750+
.await?;
751+
752+
None
753+
}
754+
};
742755

743756
let room_linked_chunk = EventLinkedChunk::with_initial_linked_chunk(
744757
linked_chunk,

0 commit comments

Comments
 (0)