From ef30f87fd1bbd9d3bc2271113876a62e14876de8 Mon Sep 17 00:00:00 2001 From: Lei Xu Date: Thu, 4 Jul 2024 14:53:49 -0700 Subject: [PATCH] chore: propagate error for table index stats (#1426) --- rust/lancedb/src/table.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/rust/lancedb/src/table.rs b/rust/lancedb/src/table.rs index 2e40cb47e8..68eb298582 100644 --- a/rust/lancedb/src/table.rs +++ b/rust/lancedb/src/table.rs @@ -1277,22 +1277,25 @@ impl NativeTable { /// Get statistics about an index. /// Returns an error if the index does not exist. - pub async fn index_stats>( + pub async fn index_stats( &self, - index_name: S, + index_name: impl AsRef, ) -> Result> { - self.dataset + let stats = match self + .dataset .get() .await? .index_statistics(index_name.as_ref()) .await - .ok() - .map(|stats| { - serde_json::from_str(&stats).map_err(|e| Error::InvalidInput { - message: format!("error deserializing index statistics: {}", e), - }) - }) - .transpose() + { + Ok(stats) => stats, + Err(lance::error::Error::IndexNotFound { .. }) => return Ok(None), + Err(e) => return Err(Error::from(e)), + }; + + serde_json::from_str(&stats).map_err(|e| Error::InvalidInput { + message: format!("error deserializing index statistics: {}", e), + }) } pub async fn load_indices(&self) -> Result> {