From 00f6af647521c0965ed9cfb178ecf3f0d0c60282 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 18 Jan 2023 17:26:48 +0100 Subject: [PATCH] fix a wrong error message --- meilisearch/src/error.rs | 4 ++-- meilisearch/tests/swap_indexes/errors.rs | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/meilisearch/src/error.rs b/meilisearch/src/error.rs index 9c77f4d3e..fcfe4b7fc 100644 --- a/meilisearch/src/error.rs +++ b/meilisearch/src/error.rs @@ -24,8 +24,8 @@ pub enum MeilisearchHttpError { MissingPayload(PayloadType), #[error("The provided payload reached the size limit.")] PayloadTooLarge, - #[error("Two indexes must be given for each swap. The list `{:?}` contains {} indexes.", - .0, .0.len() + #[error("Two indexes must be given for each swap. The list `[{}]` contains {} indexes.", + .0.iter().map(|uid| format!("\"{uid}\"")).collect::>().join(", "), .0.len() )] SwapIndexPayloadWrongLength(Vec), #[error(transparent)] diff --git a/meilisearch/tests/swap_indexes/errors.rs b/meilisearch/tests/swap_indexes/errors.rs index a2697a37d..848f347f8 100644 --- a/meilisearch/tests/swap_indexes/errors.rs +++ b/meilisearch/tests/swap_indexes/errors.rs @@ -17,6 +17,7 @@ async fn swap_indexes_bad_format() { "link": "https://docs.meilisearch.com/errors#bad-request" } "###); + let (response, code) = server.index_swap(json!(["doggo"])).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -43,16 +44,30 @@ async fn swap_indexes_bad_indexes() { "link": "https://docs.meilisearch.com/errors#invalid-swap-indexes" } "###); + let (response, code) = server.index_swap(json!([{ "indexes": ["doggo"]}])).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" { - "message": "Two indexes must be given for each swap. The list `[IndexUid(\"doggo\")]` contains 1 indexes.", + "message": "Two indexes must be given for each swap. The list `[\"doggo\"]` contains 1 indexes.", "code": "invalid_swap_indexes", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#invalid-swap-indexes" } "###); + + let (response, code) = + server.index_swap(json!([{ "indexes": ["doggo", "crabo", "croco"]}])).await; + snapshot!(code, @"400 Bad Request"); + snapshot!(json_string!(response), @r###" + { + "message": "Two indexes must be given for each swap. The list `[\"doggo\", \"crabo\", \"croco\"]` contains 3 indexes.", + "code": "invalid_swap_indexes", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#invalid-swap-indexes" + } + "###); + let (response, code) = server.index_swap(json!([{ "indexes": ["doggo", "doggo"]}])).await; snapshot!(code, @"400 Bad Request"); snapshot!(json_string!(response), @r###" @@ -63,6 +78,7 @@ async fn swap_indexes_bad_indexes() { "link": "https://docs.meilisearch.com/errors#invalid-swap-duplicate-index-found" } "###); + let (response, code) = server .index_swap(json!([{ "indexes": ["doggo", "catto"]}, { "indexes": ["girafo", "doggo"]}])) .await;