From e736a74729c3e7353b2af5d40e839a6a7fe61236 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Mon, 18 Nov 2024 12:41:51 +0100 Subject: [PATCH] Remove infinite loop in `import_vectors` --- crates/milli/src/update/new/document.rs | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/crates/milli/src/update/new/document.rs b/crates/milli/src/update/new/document.rs index ddf508ad7..ae9aa9de9 100644 --- a/crates/milli/src/update/new/document.rs +++ b/crates/milli/src/update/new/document.rs @@ -70,28 +70,30 @@ impl<'t, Mapper: FieldIdMapper> Document<'t> for DocumentFromDb<'t, Mapper> { fn iter_top_level_fields(&self) -> impl Iterator> { let mut it = self.content.iter(); - std::iter::from_fn(move || { + std::iter::from_fn(move || loop { let (fid, value) = it.next()?; + let name = match self.fields_ids_map.name(fid).ok_or( + InternalError::FieldIdMapMissingEntry(crate::FieldIdMapMissingEntry::FieldId { + field_id: fid, + process: "getting current document", + }), + ) { + Ok(name) => name, + Err(error) => return Some(Err(error.into())), + }; - let res = (|| loop { - let name = self.fields_ids_map.name(fid).ok_or( - InternalError::FieldIdMapMissingEntry(crate::FieldIdMapMissingEntry::FieldId { - field_id: fid, - process: "getting current document", - }), - )?; - - if name == RESERVED_VECTORS_FIELD_NAME || name == "_geo" { - continue; - } + if name == RESERVED_VECTORS_FIELD_NAME || name == "_geo" { + continue; + } + let res = (|| { let value = serde_json::from_slice(value).map_err(crate::InternalError::SerdeJson)?; - return Ok((name, value)); + Ok((name, value)) })(); - Some(res) + return Some(res); }) }