mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-06 04:36:32 +00:00
fix error code and add a bunch of tests for the swap and index rename
This commit is contained in:
@ -67,8 +67,8 @@ pub enum Error {
|
||||
SwapDuplicateIndexesFound(Vec<String>),
|
||||
#[error("Index `{0}` not found.")]
|
||||
SwapIndexNotFound(String),
|
||||
#[error("Index `{0}` found during a rename. Renaming doen't overwrite the other index name.")]
|
||||
SwapIndexFoundDuringRename(String),
|
||||
#[error("Cannot rename `{0}` to `{1}` as the index already exists. Hint: You can remove `{1}` first and then do your remove.")]
|
||||
SwapIndexFoundDuringRename(String, String),
|
||||
#[error("Meilisearch cannot receive write operations because the limit of the task database has been reached. Please delete tasks to continue performing write operations.")]
|
||||
NoSpaceLeftInTaskQueue,
|
||||
#[error(
|
||||
@ -76,7 +76,7 @@ pub enum Error {
|
||||
.0.iter().map(|s| format!("`{}`", s)).collect::<Vec<_>>().join(", ")
|
||||
)]
|
||||
SwapIndexesNotFound(Vec<String>),
|
||||
#[error("Index {} found during a rename. Renaming doen't overwrite the other index name.",
|
||||
#[error("The following indexes are being renamed but cannot because their new name conflicts with an already existing index: {}. Renaming doesn't overwrite the other index name.",
|
||||
.0.iter().map(|s| format!("`{}`", s)).collect::<Vec<_>>().join(", ")
|
||||
)]
|
||||
SwapIndexesFoundDuringRename(Vec<String>),
|
||||
@ -209,7 +209,7 @@ impl Error {
|
||||
| Error::SwapIndexNotFound(_)
|
||||
| Error::NoSpaceLeftInTaskQueue
|
||||
| Error::SwapIndexesNotFound(_)
|
||||
| Error::SwapIndexFoundDuringRename(_)
|
||||
| Error::SwapIndexFoundDuringRename(_, _)
|
||||
| Error::SwapIndexesFoundDuringRename(_)
|
||||
| Error::CorruptedDump
|
||||
| Error::InvalidTaskDate { .. }
|
||||
@ -279,8 +279,8 @@ impl ErrorCode for Error {
|
||||
Error::SwapDuplicateIndexFound(_) => Code::InvalidSwapDuplicateIndexFound,
|
||||
Error::SwapIndexNotFound(_) => Code::IndexNotFound,
|
||||
Error::SwapIndexesNotFound(_) => Code::IndexNotFound,
|
||||
Error::SwapIndexFoundDuringRename(_) => Code::IndexNotFound,
|
||||
Error::SwapIndexesFoundDuringRename(_) => Code::IndexNotFound,
|
||||
Error::SwapIndexFoundDuringRename(_, _) => Code::IndexAlreadyExists,
|
||||
Error::SwapIndexesFoundDuringRename(_) => Code::IndexAlreadyExists,
|
||||
Error::InvalidTaskDate { field, .. } => (*field).into(),
|
||||
Error::InvalidTaskUid { .. } => Code::InvalidTaskUids,
|
||||
Error::InvalidBatchUid { .. } => Code::InvalidBatchUids,
|
||||
|
@ -368,7 +368,7 @@ impl IndexScheduler {
|
||||
}
|
||||
let index_exists = self.index_mapper.index_exists(&wtxn, rhs)?;
|
||||
match (index_exists, rename) {
|
||||
(true, true) => found_indexes_but_should_not.insert(rhs),
|
||||
(true, true) => found_indexes_but_should_not.insert((lhs, rhs)),
|
||||
(false, false) => not_found_indexes.insert(rhs),
|
||||
(true, false) | (false, true) => true, // random value we don't read it anyway
|
||||
};
|
||||
@ -386,12 +386,18 @@ impl IndexScheduler {
|
||||
}
|
||||
if !found_indexes_but_should_not.is_empty() {
|
||||
if found_indexes_but_should_not.len() == 1 {
|
||||
return Err(Error::SwapIndexFoundDuringRename(
|
||||
found_indexes_but_should_not.into_iter().next().unwrap().clone(),
|
||||
));
|
||||
let (lhs, rhs) = found_indexes_but_should_not
|
||||
.into_iter()
|
||||
.next()
|
||||
.map(|(lhs, rhs)| (lhs.clone(), rhs.clone()))
|
||||
.unwrap();
|
||||
return Err(Error::SwapIndexFoundDuringRename(lhs, rhs));
|
||||
} else {
|
||||
return Err(Error::SwapIndexesFoundDuringRename(
|
||||
found_indexes_but_should_not.into_iter().cloned().collect(),
|
||||
found_indexes_but_should_not
|
||||
.into_iter()
|
||||
.map(|(_, rhs)| rhs.to_string())
|
||||
.collect(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user