Box the large GeoError error variant

This commit is contained in:
Clément Renault
2025-04-01 11:26:17 +02:00
parent 4d90e3d2ec
commit 64477aac60
5 changed files with 45 additions and 24 deletions

View File

@ -115,7 +115,7 @@ pub fn enrich_documents_batch<R: Read + Seek>(
if let Some(geo_value) = geo_field_id.and_then(|fid| document.get(fid)) {
if let Err(user_error) = validate_geo_from_json(&document_id, geo_value)? {
return Ok(Err(UserError::from(user_error)));
return Ok(Err(UserError::from(Box::new(user_error))));
}
}

View File

@ -80,22 +80,28 @@ fn extract_lat_lng(
let (lat, lng) = match (lat, lng) {
(Some(lat), Some(lng)) => (lat, lng),
(Some(_), None) => {
return Err(GeoError::MissingLatitude { document_id: document_id() }.into())
return Err(
Box::new(GeoError::MissingLatitude { document_id: document_id() }).into()
)
}
(None, Some(_)) => {
return Err(GeoError::MissingLongitude { document_id: document_id() }.into())
return Err(
Box::new(GeoError::MissingLongitude { document_id: document_id() }).into()
)
}
(None, None) => return Ok(None),
};
let lat = extract_finite_float_from_value(
serde_json::from_slice(lat).map_err(InternalError::SerdeJson)?,
)
.map_err(|lat| GeoError::BadLatitude { document_id: document_id(), value: lat })?;
.map_err(|lat| GeoError::BadLatitude { document_id: document_id(), value: lat })
.map_err(Box::new)?;
let lng = extract_finite_float_from_value(
serde_json::from_slice(lng).map_err(InternalError::SerdeJson)?,
)
.map_err(|lng| GeoError::BadLongitude { document_id: document_id(), value: lng })?;
.map_err(|lng| GeoError::BadLongitude { document_id: document_id(), value: lng })
.map_err(Box::new)?;
Ok(Some([lat, lng]))
}
None => Ok(None),