From 766dd830ae9434fa0da1bfd7e5fdec3973a3ef82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Thu, 12 Jan 2023 15:35:03 +0100 Subject: [PATCH] Update deserr to latest version + add new error codes for missing fields - missing_api_key_indexes - missing_api_key_actions - missing_api_key_expires_at - missing_swap_indexes_indexes --- Cargo.lock | 16 ++----- meilisearch-types/Cargo.toml | 4 +- meilisearch-types/src/error.rs | 49 ++++++++++++++++++-- meilisearch-types/src/keys.rs | 14 +++--- meilisearch-types/src/lib.rs | 1 - meilisearch-types/src/settings.rs | 31 ++++++++----- meilisearch/Cargo.toml | 2 +- meilisearch/src/routes/api_key.rs | 4 +- meilisearch/src/routes/indexes/documents.rs | 10 ++-- meilisearch/src/routes/indexes/mod.rs | 4 +- meilisearch/src/routes/indexes/search.rs | 34 +++++++------- meilisearch/src/routes/swap_indexes.rs | 2 +- meilisearch/src/routes/tasks.rs | 48 +++++++++---------- meilisearch/src/search.rs | 36 +++++++------- meilisearch/tests/auth/api_keys.rs | 27 ++++------- meilisearch/tests/documents/add_documents.rs | 4 +- 16 files changed, 158 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da1ec3011..6e754abd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1025,8 +1025,6 @@ dependencies = [ [[package]] name = "deserr" version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86290491a2b5c21a1a5083da8dae831006761258fabd5617309c3eebc5f89468" dependencies = [ "deserr-internal", "serde-cs", @@ -1036,8 +1034,6 @@ dependencies = [ [[package]] name = "deserr-internal" version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7131de1c27581bc376a22166c9f570be91b76cb096be2f6aecf224c27bf7c49a" dependencies = [ "convert_case 0.5.0", "proc-macro2 1.0.49", @@ -1315,8 +1311,7 @@ dependencies = [ [[package]] name = "filter-parser" -version = "0.39.0" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.0#e6bea999740b153871f665abce869ffbb5aa94c5" +version = "0.38.0" dependencies = [ "nom", "nom_locate", @@ -1334,8 +1329,7 @@ dependencies = [ [[package]] name = "flatten-serde-json" -version = "0.39.0" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.0#e6bea999740b153871f665abce869ffbb5aa94c5" +version = "0.38.0" dependencies = [ "serde_json", ] @@ -1899,8 +1893,7 @@ dependencies = [ [[package]] name = "json-depth-checker" -version = "0.39.0" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.0#e6bea999740b153871f665abce869ffbb5aa94c5" +version = "0.38.0" dependencies = [ "serde_json", ] @@ -2448,8 +2441,7 @@ dependencies = [ [[package]] name = "milli" -version = "0.39.0" -source = "git+https://github.com/meilisearch/milli.git?tag=v0.39.0#e6bea999740b153871f665abce869ffbb5aa94c5" +version = "0.38.0" dependencies = [ "bimap", "bincode", diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index 4c0b1ca93..257ac9c2d 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -9,14 +9,14 @@ actix-web = { version = "4.2.1", default-features = false } anyhow = "1.0.65" convert_case = "0.6.0" csv = "1.1.6" -deserr = "0.1.4" +deserr = { path = "/Users/meilisearch/Documents/deserr" } either = { version = "1.6.1", features = ["serde"] } enum-iterator = "1.1.3" file-store = { path = "../file-store" } flate2 = "1.0.24" fst = "0.4.7" memmap2 = "0.5.7" -milli = { git = "https://github.com/meilisearch/milli.git", tag = "v0.39.0", default-features = false } +milli = { path = "/Users/meilisearch/Documents/milli2/milli", default-features = false } proptest = { version = "1.0.0", optional = true } proptest-derive = { version = "0.3.0", optional = true } roaring = { version = "0.10.0", features = ["serde"] } diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 2be6ffff4..0d7f126a5 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -14,7 +14,9 @@ use serde_cs::vec::CS; use crate::star_or::StarOr; -use self::deserr_codes::MissingIndexUid; +use self::deserr_codes::{ + MissingApiKeyActions, MissingApiKeyExpiresAt, MissingApiKeyIndexes, MissingIndexUid, InvalidSwapIndexes, MissingSwapIndexesIndexes, +}; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] @@ -185,7 +187,6 @@ DumpAlreadyProcessing , invalid , CONFLICT; DumpNotFound , invalid , NOT_FOUND; DumpProcessFailed , internal , INTERNAL_SERVER_ERROR; DuplicateIndexFound , invalid , BAD_REQUEST; - ImmutableApiKeyUid , invalid , BAD_REQUEST; ImmutableApiKeyKey , invalid , BAD_REQUEST; ImmutableApiKeyActions , invalid , BAD_REQUEST; @@ -193,11 +194,9 @@ ImmutableApiKeyIndexes , invalid , BAD_REQUEST; ImmutableApiKeyExpiresAt , invalid , BAD_REQUEST; ImmutableApiKeyCreatedAt , invalid , BAD_REQUEST; ImmutableApiKeyUpdatedAt , invalid , BAD_REQUEST; - ImmutableIndexUid , invalid , BAD_REQUEST; ImmutableIndexCreatedAt , invalid , BAD_REQUEST; ImmutableIndexUpdatedAt , invalid , BAD_REQUEST; - IndexAlreadyExists , invalid , CONFLICT ; IndexCreationFailed , internal , INTERNAL_SERVER_ERROR; IndexNotFound , invalid , NOT_FOUND; @@ -281,6 +280,7 @@ MissingDocumentId , invalid , BAD_REQUEST ; MissingIndexUid , invalid , BAD_REQUEST ; MissingMasterKey , authentication, UNAUTHORIZED ; MissingPayload , invalid , BAD_REQUEST ; +MissingSwapIndexesIndexes , invalid , BAD_REQUEST ; MissingTaskFilters , invalid , BAD_REQUEST ; NoSpaceLeftOnDevice , system , UNPROCESSABLE_ENTITY; PayloadTooLarge , invalid , PAYLOAD_TOO_LARGE ; @@ -478,6 +478,47 @@ impl DeserrJsonError { Self { msg: x.msg, code: MissingIndexUid.error_code(), _phantom: PhantomData } } } +impl DeserrJsonError { + pub fn missing_api_key_actions(field: &str, location: ValuePointerRef) -> Self { + let x = unwrap_any(Self::error::( + None, + deserr::ErrorKind::MissingField { field }, + location, + )); + Self { msg: x.msg, code: MissingApiKeyActions.error_code(), _phantom: PhantomData } + } +} +impl DeserrJsonError { + pub fn missing_api_key_expires_at(field: &str, location: ValuePointerRef) -> Self { + let x = unwrap_any(Self::error::( + None, + deserr::ErrorKind::MissingField { field }, + location, + )); + Self { msg: x.msg, code: MissingApiKeyExpiresAt.error_code(), _phantom: PhantomData } + } +} +impl DeserrJsonError { + pub fn missing_api_key_indexes(field: &str, location: ValuePointerRef) -> Self { + let x = unwrap_any(Self::error::( + None, + deserr::ErrorKind::MissingField { field }, + location, + )); + Self { msg: x.msg, code: MissingApiKeyIndexes.error_code(), _phantom: PhantomData } + } +} + +impl DeserrJsonError { + pub fn missing_swap_indexes_indexes(field: &str, location: ValuePointerRef) -> Self { + let x = unwrap_any(Self::error::( + None, + deserr::ErrorKind::MissingField { field }, + location, + )); + Self { msg: x.msg, code: MissingSwapIndexesIndexes.error_code(), _phantom: PhantomData } + } +} // if the error happened in the root, then an empty string is returned. pub fn location_json_description(location: ValuePointerRef, article: &str) -> String { diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index 53776e489..d736fd8c1 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -38,17 +38,17 @@ fn parse_uuid_from_str(s: &str) -> Result> { #[derive(Debug, DeserializeFromValue)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct CreateApiKey { - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub description: Option, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub name: Option, #[deserr(default = Uuid::new_v4(), error = DeserrJsonError, from(&String) = parse_uuid_from_str -> TakeErrorMessage)] pub uid: KeyId, - #[deserr(error = DeserrJsonError)] + #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_api_key_actions)] pub actions: Vec, - #[deserr(error = DeserrJsonError)] + #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_api_key_indexes)] pub indexes: Vec>, - #[deserr(error = DeserrJsonError, default = None, from(&String) = parse_expiration_date -> TakeErrorMessage)] + #[deserr(error = DeserrJsonError, from(&String) = parse_expiration_date -> TakeErrorMessage, missing_field_error = DeserrJsonError::missing_api_key_expires_at)] pub expires_at: Option, } impl CreateApiKey { @@ -94,9 +94,9 @@ fn deny_immutable_fields_api_key( #[derive(Debug, DeserializeFromValue)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_api_key)] pub struct PatchApiKey { - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub description: Option, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub name: Option, } diff --git a/meilisearch-types/src/lib.rs b/meilisearch-types/src/lib.rs index f8fc47abd..354a25fa1 100644 --- a/meilisearch-types/src/lib.rs +++ b/meilisearch-types/src/lib.rs @@ -8,7 +8,6 @@ pub mod star_or; pub mod tasks; pub mod versioning; -pub use deserr; pub use milli; pub use milli::{heed, Index}; pub use serde_cs; diff --git a/meilisearch-types/src/settings.rs b/meilisearch-types/src/settings.rs index 0a79f865e..99f4ae9e3 100644 --- a/meilisearch-types/src/settings.rs +++ b/meilisearch-types/src/settings.rs @@ -69,8 +69,10 @@ fn validate_min_word_size_for_typo_setting( #[deserr(deny_unknown_fields, rename_all = camelCase, validate = validate_min_word_size_for_typo_setting -> DeserrJsonError)] pub struct MinWordSizeTyposSetting { #[serde(default, skip_serializing_if = "Setting::is_not_set")] + #[deserr(default)] pub one_typo: Setting, #[serde(default, skip_serializing_if = "Setting::is_not_set")] + #[deserr(default)] pub two_typos: Setting, } @@ -79,13 +81,16 @@ pub struct MinWordSizeTyposSetting { #[deserr(deny_unknown_fields, rename_all = camelCase, where_predicate = __Deserr_E: deserr::MergeWithError>)] pub struct TypoSettings { #[serde(default, skip_serializing_if = "Setting::is_not_set")] + #[deserr(default)] pub enabled: Setting, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub min_word_size_for_typos: Setting, #[serde(default, skip_serializing_if = "Setting::is_not_set")] + #[deserr(default)] pub disable_on_words: Setting>, #[serde(default, skip_serializing_if = "Setting::is_not_set")] + #[deserr(default)] pub disable_on_attributes: Setting>, } @@ -94,6 +99,7 @@ pub struct TypoSettings { #[deserr(rename_all = camelCase, deny_unknown_fields)] pub struct FacetingSettings { #[serde(default, skip_serializing_if = "Setting::is_not_set")] + #[deserr(default)] pub max_values_per_facet: Setting, } @@ -102,6 +108,7 @@ pub struct FacetingSettings { #[deserr(rename_all = camelCase, deny_unknown_fields)] pub struct PaginationSettings { #[serde(default, skip_serializing_if = "Setting::is_not_set")] + #[deserr(default)] pub max_total_hits: Setting, } @@ -135,7 +142,7 @@ pub struct Settings { serialize_with = "serialize_with_wildcard", skip_serializing_if = "Setting::is_not_set" )] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub displayed_attributes: Setting>, #[serde( @@ -143,35 +150,35 @@ pub struct Settings { serialize_with = "serialize_with_wildcard", skip_serializing_if = "Setting::is_not_set" )] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub searchable_attributes: Setting>, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub filterable_attributes: Setting>, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub sortable_attributes: Setting>, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub ranking_rules: Setting>, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub stop_words: Setting>, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub synonyms: Setting>>, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub distinct_attribute: Setting, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub typo_tolerance: Setting, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub faceting: Setting, #[serde(default, skip_serializing_if = "Setting::is_not_set")] - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub pagination: Setting, #[serde(skip)] diff --git a/meilisearch/Cargo.toml b/meilisearch/Cargo.toml index be852c02e..2c2c2aca8 100644 --- a/meilisearch/Cargo.toml +++ b/meilisearch/Cargo.toml @@ -19,7 +19,7 @@ byte-unit = { version = "4.0.14", default-features = false, features = ["std", " bytes = "1.2.1" clap = { version = "4.0.9", features = ["derive", "env"] } crossbeam-channel = "0.5.6" -deserr = "0.1.4" +deserr = { path = "/Users/meilisearch/Documents/deserr" } dump = { path = "../dump" } either = "1.8.0" env_logger = "0.9.1" diff --git a/meilisearch/src/routes/api_key.rs b/meilisearch/src/routes/api_key.rs index ce4ab0696..917a5e285 100644 --- a/meilisearch/src/routes/api_key.rs +++ b/meilisearch/src/routes/api_key.rs @@ -55,10 +55,10 @@ pub async fn create_api_key( #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct ListApiKeys { #[serde(default)] - #[deserr(error = DeserrQueryParamError, default, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] pub offset: usize, #[serde(default = "PAGINATION_DEFAULT_LIMIT")] - #[deserr(error = DeserrQueryParamError, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + #[deserr(default = PAGINATION_DEFAULT_LIMIT(), error = DeserrQueryParamError, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] pub limit: usize, } impl ListApiKeys { diff --git a/meilisearch/src/routes/indexes/documents.rs b/meilisearch/src/routes/indexes/documents.rs index c09b12244..2c1b0f692 100644 --- a/meilisearch/src/routes/indexes/documents.rs +++ b/meilisearch/src/routes/indexes/documents.rs @@ -85,7 +85,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct GetDocument { // TODO: strongly typed argument here - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] fields: Option>>, } @@ -122,11 +122,11 @@ pub async fn delete_document( #[derive(Deserialize, Debug, DeserializeFromValue)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct BrowseQuery { - #[deserr(error = DeserrQueryParamError, default, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] offset: usize, - #[deserr(error = DeserrQueryParamError, default = crate::routes::PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + #[deserr(default = crate::routes::PAGINATION_DEFAULT_LIMIT(), error = DeserrQueryParamError, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] limit: usize, - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] fields: Option>>, } @@ -151,7 +151,7 @@ pub async fn get_all_documents( #[derive(Deserialize, Debug, DeserializeFromValue)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct UpdateDocumentsQuery { - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub primary_key: Option, } diff --git a/meilisearch/src/routes/indexes/mod.rs b/meilisearch/src/routes/indexes/mod.rs index 061eefaf6..216cc448e 100644 --- a/meilisearch/src/routes/indexes/mod.rs +++ b/meilisearch/src/routes/indexes/mod.rs @@ -76,10 +76,10 @@ impl IndexView { #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct ListIndexes { #[serde(default)] - #[deserr(error = DeserrQueryParamError, default, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] pub offset: usize, #[serde(default = "PAGINATION_DEFAULT_LIMIT")] - #[deserr(error = DeserrQueryParamError, default = PAGINATION_DEFAULT_LIMIT(), from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] + #[deserr(default = PAGINATION_DEFAULT_LIMIT(), error = DeserrQueryParamError, from(&String) = parse_usize_take_error_message -> TakeErrorMessage)] pub limit: usize, } impl ListIndexes { diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index 8819ac8cf..ec9364711 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -48,39 +48,39 @@ pub fn parse_bool_take_error_message( #[derive(Debug, deserr::DeserializeFromValue)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQueryGet { - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] q: Option, - #[deserr(error = DeserrQueryParamError, default = DEFAULT_SEARCH_OFFSET(), from(String) = parse_usize_query_param -> TakeErrorMessage)] + #[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrQueryParamError, from(String) = parse_usize_query_param -> TakeErrorMessage)] offset: usize, - #[deserr(error = DeserrQueryParamError, default = DEFAULT_SEARCH_LIMIT(), from(String) = parse_usize_query_param -> TakeErrorMessage)] + #[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrQueryParamError, from(String) = parse_usize_query_param -> TakeErrorMessage)] limit: usize, - #[deserr(error = DeserrQueryParamError, from(Option) = parse_option_usize_query_param -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(Option) = parse_option_usize_query_param -> TakeErrorMessage)] page: Option, - #[deserr(error = DeserrQueryParamError, from(Option) = parse_option_usize_query_param -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(Option) = parse_option_usize_query_param -> TakeErrorMessage)] hits_per_page: Option, - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] attributes_to_retrieve: Option>, - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] attributes_to_crop: Option>, - #[deserr(error = DeserrQueryParamError, default = DEFAULT_CROP_LENGTH(), from(String) = parse_usize_query_param -> TakeErrorMessage)] + #[deserr(default = DEFAULT_CROP_LENGTH(), error = DeserrQueryParamError, from(String) = parse_usize_query_param -> TakeErrorMessage)] crop_length: usize, - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] attributes_to_highlight: Option>, - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] filter: Option, - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] sort: Option, - #[deserr(error = DeserrQueryParamError, default, from(&String) = parse_bool_take_error_message -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(&String) = parse_bool_take_error_message -> TakeErrorMessage)] show_matches_position: bool, - #[deserr(error = DeserrQueryParamError)] + #[deserr(default, error = DeserrQueryParamError)] facets: Option>, - #[deserr(error = DeserrQueryParamError, default = DEFAULT_HIGHLIGHT_PRE_TAG())] + #[deserr( default = DEFAULT_HIGHLIGHT_PRE_TAG(), error = DeserrQueryParamError)] highlight_pre_tag: String, - #[deserr(error = DeserrQueryParamError, default = DEFAULT_HIGHLIGHT_POST_TAG())] + #[deserr( default = DEFAULT_HIGHLIGHT_POST_TAG(), error = DeserrQueryParamError)] highlight_post_tag: String, - #[deserr(error = DeserrQueryParamError, default = DEFAULT_CROP_MARKER())] + #[deserr(default = DEFAULT_CROP_MARKER(), error = DeserrQueryParamError)] crop_marker: String, - #[deserr(error = DeserrQueryParamError, default)] + #[deserr(default, error = DeserrQueryParamError)] matching_strategy: MatchingStrategy, } diff --git a/meilisearch/src/routes/swap_indexes.rs b/meilisearch/src/routes/swap_indexes.rs index 57015f1f1..5d6d1e1e5 100644 --- a/meilisearch/src/routes/swap_indexes.rs +++ b/meilisearch/src/routes/swap_indexes.rs @@ -22,7 +22,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { #[derive(DeserializeFromValue, Debug, Clone, PartialEq, Eq)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SwapIndexesPayload { - #[deserr(error = DeserrJsonError)] + #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_swap_indexes_indexes)] indexes: Vec, } diff --git a/meilisearch/src/routes/tasks.rs b/meilisearch/src/routes/tasks.rs index dbf1380e2..d9c498e4e 100644 --- a/meilisearch/src/routes/tasks.rs +++ b/meilisearch/src/routes/tasks.rs @@ -169,61 +169,61 @@ impl From
for DetailsView { #[derive(Debug, DeserializeFromValue)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct TasksFilterQuery { - #[deserr(error = DeserrQueryParamError, default = DEFAULT_LIMIT(), from(String) = parse_u32_query_param -> TakeErrorMessage)] + #[deserr(default = DEFAULT_LIMIT(), error = DeserrQueryParamError, from(String) = parse_u32_query_param -> TakeErrorMessage)] pub limit: u32, - #[deserr(error = DeserrQueryParamError, from(Option) = parse_option_u32_query_param -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(Option) = parse_option_u32_query_param -> TakeErrorMessage)] pub from: Option, - #[deserr(error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] pub uids: Option>, - #[deserr(error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] pub canceled_by: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] pub types: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] pub statuses: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] pub index_uids: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] pub after_enqueued_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] pub before_enqueued_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] pub after_started_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] pub before_started_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] pub after_finished_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] pub before_finished_at: Option, } #[derive(Deserialize, Debug, DeserializeFromValue)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct TaskDeletionOrCancelationQuery { - #[deserr(error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] pub uids: Option>, - #[deserr(error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, from(Option>) = parse_option_vec_u32_query_param -> TakeErrorMessage)] pub canceled_by: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] pub types: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] pub statuses: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option>>) = parse_option_cs_star_or:: -> TakeErrorMessage)] pub index_uids: Option>, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] pub after_enqueued_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] pub before_enqueued_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] pub after_started_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] pub before_started_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_after -> TakeErrorMessage)] pub after_finished_at: Option, - #[deserr(error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] + #[deserr(default, error = DeserrQueryParamError, default = None, from(Option) = deserialize_date_before -> TakeErrorMessage)] pub before_finished_at: Option, } diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 4e2c43f18..bfb0bf160 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -3,8 +3,8 @@ use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::str::FromStr; use std::time::Instant; +use deserr::DeserializeFromValue; use either::Either; -use meilisearch_types::deserr::DeserializeFromValue; use meilisearch_types::error::deserr_codes::*; use meilisearch_types::error::DeserrJsonError; use meilisearch_types::settings::DEFAULT_PAGINATION_MAX_TOTAL_HITS; @@ -32,39 +32,39 @@ pub const DEFAULT_HIGHLIGHT_POST_TAG: fn() -> String = || "".to_string(); #[derive(Debug, Clone, Default, PartialEq, DeserializeFromValue)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQuery { - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub q: Option, - #[deserr(error = DeserrJsonError, default = DEFAULT_SEARCH_OFFSET())] + #[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrJsonError)] pub offset: usize, - #[deserr(error = DeserrJsonError, default = DEFAULT_SEARCH_LIMIT())] + #[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrJsonError)] pub limit: usize, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub page: Option, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub hits_per_page: Option, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub attributes_to_retrieve: Option>, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub attributes_to_crop: Option>, - #[deserr(error = DeserrJsonError, default = DEFAULT_CROP_LENGTH())] + #[deserr(default, error = DeserrJsonError, default = DEFAULT_CROP_LENGTH())] pub crop_length: usize, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub attributes_to_highlight: Option>, - #[deserr(error = DeserrJsonError, default)] + #[deserr(default, error = DeserrJsonError, default)] pub show_matches_position: bool, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub filter: Option, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub sort: Option>, - #[deserr(error = DeserrJsonError)] + #[deserr(default, error = DeserrJsonError)] pub facets: Option>, - #[deserr(error = DeserrJsonError, default = DEFAULT_HIGHLIGHT_PRE_TAG())] + #[deserr(default, error = DeserrJsonError, default = DEFAULT_HIGHLIGHT_PRE_TAG())] pub highlight_pre_tag: String, - #[deserr(error = DeserrJsonError, default = DEFAULT_HIGHLIGHT_POST_TAG())] + #[deserr(default, error = DeserrJsonError, default = DEFAULT_HIGHLIGHT_POST_TAG())] pub highlight_post_tag: String, - #[deserr(error = DeserrJsonError, default = DEFAULT_CROP_MARKER())] + #[deserr(default, error = DeserrJsonError, default = DEFAULT_CROP_MARKER())] pub crop_marker: String, - #[deserr(error = DeserrJsonError, default)] + #[deserr(default, error = DeserrJsonError, default)] pub matching_strategy: MatchingStrategy, } diff --git a/meilisearch/tests/auth/api_keys.rs b/meilisearch/tests/auth/api_keys.rs index 8d7cb9130..03910c0a9 100644 --- a/meilisearch/tests/auth/api_keys.rs +++ b/meilisearch/tests/auth/api_keys.rs @@ -249,9 +249,9 @@ async fn error_add_api_key_missing_parameter() { meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###" { "message": "Missing field `indexes`", - "code": "bad_request", + "code": "missing_api_key_indexes", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#bad-request" + "link": "https://docs.meilisearch.com/errors#missing-api-key-indexes" } "###); @@ -266,9 +266,9 @@ async fn error_add_api_key_missing_parameter() { meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]" }), @r###" { "message": "Missing field `actions`", - "code": "bad_request", + "code": "missing_api_key_actions", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#bad-request" + "link": "https://docs.meilisearch.com/errors#missing-api-key-actions" } "###); @@ -279,22 +279,13 @@ async fn error_add_api_key_missing_parameter() { "actions": ["documents.add"], }); let (response, code) = server.add_api_key(content).await; - meili_snap::snapshot!(code, @"201 Created"); + meili_snap::snapshot!(code, @"400 Bad Request"); meili_snap::snapshot!(meili_snap::json_string!(response, { ".createdAt" => "[ignored]", ".updatedAt" => "[ignored]", ".uid" => "[ignored]", ".key" => "[ignored]" }), @r###" { - "name": null, - "description": "Indexing API key", - "key": "[ignored]", - "uid": "[ignored]", - "actions": [ - "documents.add" - ], - "indexes": [ - "products" - ], - "expiresAt": null, - "createdAt": "[ignored]", - "updatedAt": "[ignored]" + "message": "Missing field `expiresAt`", + "code": "missing_api_key_expires_at", + "type": "invalid_request", + "link": "https://docs.meilisearch.com/errors#missing-api-key-expires-at" } "###); } diff --git a/meilisearch/tests/documents/add_documents.rs b/meilisearch/tests/documents/add_documents.rs index 4af365a7e..c27b899c6 100644 --- a/meilisearch/tests/documents/add_documents.rs +++ b/meilisearch/tests/documents/add_documents.rs @@ -926,7 +926,7 @@ async fn error_primary_key_inference() { "indexedDocuments": 1 }, "error": { - "message": "The primary key inference failed as the engine did not find any field ending with `id` in its name. Please specify the primary key manually using the `primaryKey` query parameter.", + "message": "The primary key inference process failed because the engine did not find any field ending with `id` in its name. Please specify the primary key manually using the `primaryKey` query parameter.", "code": "index_primary_key_no_candidate_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index-primary-key-no-candidate-found" @@ -966,7 +966,7 @@ async fn error_primary_key_inference() { "indexedDocuments": 1 }, "error": { - "message": "The primary key inference failed as the engine found 3 fields ending with `id` in their names: 'id' and 'object_id'. Please specify the primary key manually using the `primaryKey` query parameter.", + "message": "The primary key inference process failed because the engine found 3 fields ending with `id` in their name, such as 'id' and 'object_id'. Please specify the primary key manually using the `primaryKey` query parameter.", "code": "index_primary_key_multiple_candidates_found", "type": "invalid_request", "link": "https://docs.meilisearch.com/errors#index-primary-key-multiple-candidates-found"