From bedcbfd7ff7cb5d5f817c8bd8f9d2089042a1f62 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 3 Jul 2025 11:07:23 +0200 Subject: [PATCH] fix(event cache): don't return an error when a linked chunk is empty The metadata loading shouldn't cause an error to be displayed, when the linked chunk is empty; this can happen for new rooms we've never visited. Spotted while investigating some failures in a rageshake. --- crates/matrix-sdk/src/event_cache/room/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk/src/event_cache/room/mod.rs b/crates/matrix-sdk/src/event_cache/room/mod.rs index 62aca0805..a05571437 100644 --- a/crates/matrix-sdk/src/event_cache/room/mod.rs +++ b/crates/matrix-sdk/src/event_cache/room/mod.rs @@ -600,7 +600,7 @@ mod private { // indicates that at some point, there's some malformed data. let full_linked_chunk_metadata = match Self::load_linked_chunk_metadata(&*store_lock, linked_chunk_id).await { - Ok(metas) => Some(metas), + Ok(metas) => metas, Err(err) => { error!( "error when loading a linked chunk's metadata from the store: {err}" @@ -650,12 +650,17 @@ mod private { async fn load_linked_chunk_metadata( store: &DynEventCacheStore, linked_chunk_id: LinkedChunkId<'_>, - ) -> Result, EventCacheError> { + ) -> Result>, EventCacheError> { let mut all_chunks = store .load_all_chunks_metadata(linked_chunk_id) .await .map_err(EventCacheError::from)?; + if all_chunks.is_empty() { + // There are no chunks, so there's nothing to do. + return Ok(None); + } + // Transform the vector into a hashmap, for quick lookup of the predecessors. let chunk_map: HashMap<_, _> = all_chunks.iter().map(|meta| (meta.identifier, meta)).collect(); @@ -759,7 +764,7 @@ mod private { } } - Ok(all_chunks) + Ok(Some(all_chunks)) } /// Given a fully-loaded linked chunk with no gaps, return the