From 72c506d8f6228e4db0081a649c84b6fb6fca0b70 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Mon, 31 Mar 2025 16:34:58 +0200 Subject: [PATCH] Improve the error message by categorizing NoSpaceLeftOnDevice --- crates/meilisearch-types/src/error.rs | 2 +- crates/milli/src/error.rs | 4 ++-- crates/milli/src/update/new/extract/cache.rs | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/meilisearch-types/src/error.rs b/crates/meilisearch-types/src/error.rs index 859563d8a..757aacdbf 100644 --- a/crates/meilisearch-types/src/error.rs +++ b/crates/meilisearch-types/src/error.rs @@ -411,7 +411,7 @@ impl ErrorCode for milli::Error { | UserError::DocumentLimitReached | UserError::UnknownInternalDocumentId { .. } => Code::Internal, UserError::InvalidStoreFile => Code::InvalidStoreFile, - UserError::NoSpaceLeftOnDevice => Code::NoSpaceLeftOnDevice, + UserError::NoSpaceLeftOnDevice { .. } => Code::NoSpaceLeftOnDevice, UserError::MaxDatabaseSizeReached => Code::DatabaseSizeLimitReached, UserError::AttributeLimitReached => Code::MaxFieldsLimitExceeded, UserError::InvalidFilter(_) => Code::InvalidSearchFilter, diff --git a/crates/milli/src/error.rs b/crates/milli/src/error.rs index e2f8fb6e4..67f9fe223 100644 --- a/crates/milli/src/error.rs +++ b/crates/milli/src/error.rs @@ -259,8 +259,8 @@ and can not be more than 511 bytes.", .document_id.to_string() NoPrimaryKeyCandidateFound, #[error("The primary key inference failed as the engine found {} fields ending with `id` in their names: '{}' and '{}'. Please specify the primary key manually using the `primaryKey` query parameter.", .candidates.len(), .candidates.first().unwrap(), .candidates.get(1).unwrap())] MultiplePrimaryKeyCandidatesFound { candidates: Vec }, - #[error("There is no more space left on the device. Consider increasing the size of the disk/partition.")] - NoSpaceLeftOnDevice, + #[error("There is no more space left on the device ({source_}). Consider increasing the size of the disk/partition.")] + NoSpaceLeftOnDevice { source_: &'static str }, #[error("Index already has a primary key: `{0}`.")] PrimaryKeyCannotBeChanged(String), #[error(transparent)] diff --git a/crates/milli/src/update/new/extract/cache.rs b/crates/milli/src/update/new/extract/cache.rs index f9829032b..82a8b9fbc 100644 --- a/crates/milli/src/update/new/extract/cache.rs +++ b/crates/milli/src/update/new/extract/cache.rs @@ -417,25 +417,33 @@ fn spill_entry_to_sorter( deladd_buffer.clear(); let mut value_writer = KvWriterDelAdd::new(deladd_buffer); + fn convert_io_to_user_error(error: io::Error) -> crate::Error { + if error.kind() == io::ErrorKind::StorageFull { + crate::Error::UserError(crate::UserError::NoSpaceLeftOnDevice { source_: "grenad" }) + } else { + crate::Error::IoError(error) + } + } + match deladd { DelAddRoaringBitmap { del: Some(del), add: None } => { cbo_buffer.clear(); CboRoaringBitmapCodec::serialize_into_vec(&del, cbo_buffer); - value_writer.insert(DelAdd::Deletion, &cbo_buffer)?; + value_writer.insert(DelAdd::Deletion, &cbo_buffer).map_err(convert_io_to_user_error)?; } DelAddRoaringBitmap { del: None, add: Some(add) } => { cbo_buffer.clear(); CboRoaringBitmapCodec::serialize_into_vec(&add, cbo_buffer); - value_writer.insert(DelAdd::Addition, &cbo_buffer)?; + value_writer.insert(DelAdd::Addition, &cbo_buffer).map_err(convert_io_to_user_error)?; } DelAddRoaringBitmap { del: Some(del), add: Some(add) } => { cbo_buffer.clear(); CboRoaringBitmapCodec::serialize_into_vec(&del, cbo_buffer); - value_writer.insert(DelAdd::Deletion, &cbo_buffer)?; + value_writer.insert(DelAdd::Deletion, &cbo_buffer).map_err(convert_io_to_user_error)?; cbo_buffer.clear(); CboRoaringBitmapCodec::serialize_into_vec(&add, cbo_buffer); - value_writer.insert(DelAdd::Addition, &cbo_buffer)?; + value_writer.insert(DelAdd::Addition, &cbo_buffer).map_err(convert_io_to_user_error)?; } DelAddRoaringBitmap { del: None, add: None } => return Ok(()), }