From d3086843958c0c22a0bdd638f2cbbf53b7488439 Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 9 Jan 2023 18:59:09 +0100 Subject: [PATCH] remove two ununsed error codes + fix the sort error_code --- dump/src/reader/compat/v5_to_v6.rs | 9 ++-- meilisearch-types/src/error.rs | 27 ++--------- meilisearch/src/error.rs | 2 +- meilisearch/tests/search/errors.rs | 56 +++++++++++----------- meilisearch/tests/settings/get_settings.rs | 4 +- meilisearch/tests/tasks/mod.rs | 4 +- 6 files changed, 42 insertions(+), 60 deletions(-) diff --git a/dump/src/reader/compat/v5_to_v6.rs b/dump/src/reader/compat/v5_to_v6.rs index 571490980..0216d490e 100644 --- a/dump/src/reader/compat/v5_to_v6.rs +++ b/dump/src/reader/compat/v5_to_v6.rs @@ -265,15 +265,15 @@ impl From for v6::ResponseError { "max_fields_limit_exceeded" => v6::Code::MaxFieldsLimitExceeded, "missing_document_id" => v6::Code::MissingDocumentId, "invalid_document_id" => v6::Code::InvalidDocumentId, - "invalid_filter" => v6::Code::Filter, - "invalid_sort" => v6::Code::Sort, + "invalid_filter" => v6::Code::InvalidSettingsFilterableAttributes, + "invalid_sort" => v6::Code::InvalidSettingsSortableAttributes, "bad_parameter" => v6::Code::BadParameter, "bad_request" => v6::Code::BadRequest, "database_size_limit_reached" => v6::Code::DatabaseSizeLimitReached, "document_not_found" => v6::Code::DocumentNotFound, "internal" => v6::Code::Internal, "invalid_geo_field" => v6::Code::InvalidDocumentGeoField, - "invalid_ranking_rule" => v6::Code::InvalidRankingRule, + "invalid_ranking_rule" => v6::Code::InvalidSettingsRankingRules, "invalid_store_file" => v6::Code::InvalidStore, "invalid_api_key" => v6::Code::InvalidToken, "missing_authorization_header" => v6::Code::MissingAuthorizationHeader, @@ -281,8 +281,7 @@ impl From for v6::ResponseError { "dump_not_found" => v6::Code::DumpNotFound, "task_not_found" => v6::Code::TaskNotFound, "payload_too_large" => v6::Code::PayloadTooLarge, - "unretrievable_document" => v6::Code::RetrieveDocument, - "search_error" => v6::Code::SearchDocuments, + "unretrievable_document" => v6::Code::DocumentNotFound, "unsupported_media_type" => v6::Code::UnsupportedMediaType, "dump_already_processing" => v6::Code::DumpAlreadyInProgress, "dump_process_failed" => v6::Code::DumpProcessFailed, diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index bd06e69e9..3c4f65e6b 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -141,9 +141,6 @@ pub enum Code { MissingDocumentId, InvalidDocumentId, - Filter, - Sort, - // Invalid swap-indexes InvalidSwapIndexes, InvalidDuplicateIndexesFound, @@ -205,7 +202,6 @@ pub enum Code { DocumentNotFound, Internal, InvalidDocumentGeoField, - InvalidRankingRule, InvalidStore, InvalidToken, MissingAuthorizationHeader, @@ -215,8 +211,6 @@ pub enum Code { TaskDeletionWithEmptyQuery, TaskCancelationWithEmptyQuery, PayloadTooLarge, - RetrieveDocument, - SearchDocuments, UnsupportedMediaType, DumpAlreadyInProgress, @@ -292,8 +286,6 @@ impl Code { PrimaryKeyAlreadyPresent => { ErrCode::invalid("index_primary_key_already_exists", StatusCode::BAD_REQUEST) } - // invalid ranking rule - InvalidRankingRule => ErrCode::invalid("invalid_ranking_rule", StatusCode::BAD_REQUEST), // invalid database InvalidStore => { @@ -307,11 +299,6 @@ impl Code { MissingDocumentId => ErrCode::invalid("missing_document_id", StatusCode::BAD_REQUEST), InvalidDocumentId => ErrCode::invalid("invalid_document_id", StatusCode::BAD_REQUEST), - // error related to filters - Filter => ErrCode::invalid("invalid_filter", StatusCode::BAD_REQUEST), - // error related to sorts - Sort => ErrCode::invalid("invalid_sort", StatusCode::BAD_REQUEST), - BadParameter => ErrCode::invalid("bad_parameter", StatusCode::BAD_REQUEST), BadRequest => ErrCode::invalid("bad_request", StatusCode::BAD_REQUEST), DatabaseSizeLimitReached => { @@ -338,10 +325,6 @@ impl Code { } DumpNotFound => ErrCode::invalid("dump_not_found", StatusCode::NOT_FOUND), PayloadTooLarge => ErrCode::invalid("payload_too_large", StatusCode::PAYLOAD_TOO_LARGE), - RetrieveDocument => { - ErrCode::internal("unretrievable_document", StatusCode::BAD_REQUEST) - } - SearchDocuments => ErrCode::internal("search_error", StatusCode::BAD_REQUEST), UnsupportedMediaType => { ErrCode::invalid("unsupported_media_type", StatusCode::UNSUPPORTED_MEDIA_TYPE) } @@ -612,7 +595,7 @@ impl ErrorCode for milli::Error { UserError::NoSpaceLeftOnDevice => Code::NoSpaceLeftOnDevice, UserError::MaxDatabaseSizeReached => Code::DatabaseSizeLimitReached, UserError::AttributeLimitReached => Code::MaxFieldsLimitExceeded, - UserError::InvalidFilter(_) => Code::Filter, + UserError::InvalidFilter(_) => Code::InvalidSearchFilter, UserError::MissingDocumentId { .. } => Code::MissingDocumentId, UserError::InvalidDocumentId { .. } | UserError::TooManyDocumentIds { .. } => { Code::InvalidDocumentId @@ -622,12 +605,12 @@ impl ErrorCode for milli::Error { Code::MultiplePrimaryKeyCandidatesFound } UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent, - UserError::SortRankingRuleMissing => Code::Sort, + UserError::SortRankingRuleMissing => Code::InvalidSearchSort, UserError::InvalidFacetsDistribution { .. } => Code::BadRequest, - UserError::InvalidSortableAttribute { .. } => Code::Sort, - UserError::CriterionError(_) => Code::InvalidRankingRule, + UserError::InvalidSortableAttribute { .. } => Code::InvalidSearchSort, + UserError::CriterionError(_) => Code::InvalidSettingsRankingRules, UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField, - UserError::SortError(_) => Code::Sort, + UserError::SortError(_) => Code::InvalidSearchSort, UserError::InvalidMinTypoWordLenSetting(_, _) => { Code::InvalidMinWordLengthForTypo } diff --git a/meilisearch/src/error.rs b/meilisearch/src/error.rs index bec233971..23a101080 100644 --- a/meilisearch/src/error.rs +++ b/meilisearch/src/error.rs @@ -55,7 +55,7 @@ impl ErrorCode for MeilisearchHttpError { MeilisearchHttpError::MissingPayload(_) => Code::MissingPayload, MeilisearchHttpError::InvalidContentType(_, _) => Code::InvalidContentType, MeilisearchHttpError::DocumentNotFound(_) => Code::DocumentNotFound, - MeilisearchHttpError::InvalidExpression(_, _) => Code::Filter, + MeilisearchHttpError::InvalidExpression(_, _) => Code::InvalidSearchFilter, MeilisearchHttpError::PayloadTooLarge => Code::PayloadTooLarge, MeilisearchHttpError::SwapIndexPayloadWrongLength(_) => Code::InvalidSwapIndexes, MeilisearchHttpError::IndexUid(e) => e.error_code(), diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 163a63d6f..f9b691415 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -151,9 +151,9 @@ async fn filter_invalid_syntax_object() { let expected_response = json!({ "message": "Was expecting an operation `=`, `!=`, `>=`, `>`, `<=`, `<`, `IN`, `NOT IN`, `TO`, `EXISTS`, `NOT EXISTS`, or `_geoRadius` at `title & Glass`.\n1:14 title & Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": "title & Glass"}), |response, code| { @@ -176,9 +176,9 @@ async fn filter_invalid_syntax_array() { let expected_response = json!({ "message": "Was expecting an operation `=`, `!=`, `>=`, `>`, `<=`, `<`, `IN`, `NOT IN`, `TO`, `EXISTS`, `NOT EXISTS`, or `_geoRadius` at `title & Glass`.\n1:14 title & Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": ["title & Glass"]}), |response, code| { @@ -201,9 +201,9 @@ async fn filter_invalid_syntax_string() { let expected_response = json!({ "message": "Found unexpected characters at the end of the filter: `XOR title = Glass`. You probably forgot an `OR` or an `AND` rule.\n15:32 title = Glass XOR title = Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": "title = Glass XOR title = Glass"}), |response, code| { @@ -226,9 +226,9 @@ async fn filter_invalid_attribute_array() { let expected_response = json!({ "message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": ["many = Glass"]}), |response, code| { @@ -251,9 +251,9 @@ async fn filter_invalid_attribute_string() { let expected_response = json!({ "message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": "many = Glass"}), |response, code| { @@ -276,9 +276,9 @@ async fn filter_reserved_geo_attribute_array() { let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the _geoRadius(latitude, longitude, distance) built-in rule to filter on _geo field coordinates.\n1:5 _geo = Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": ["_geo = Glass"]}), |response, code| { @@ -301,9 +301,9 @@ async fn filter_reserved_geo_attribute_string() { let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a filter expression. Use the _geoRadius(latitude, longitude, distance) built-in rule to filter on _geo field coordinates.\n1:5 _geo = Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": "_geo = Glass"}), |response, code| { @@ -326,9 +326,9 @@ async fn filter_reserved_attribute_array() { let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression.\n1:13 _geoDistance = Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": ["_geoDistance = Glass"]}), |response, code| { @@ -351,9 +351,9 @@ async fn filter_reserved_attribute_string() { let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression.\n1:13 _geoDistance = Glass", - "code": "invalid_filter", + "code": "invalid_search_filter", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-filter" + "link": "https://docs.meilisearch.com/errors#invalid-search-filter" }); index .search(json!({"filter": "_geoDistance = Glass"}), |response, code| { @@ -376,9 +376,9 @@ async fn sort_geo_reserved_attribute() { let expected_response = json!({ "message": "`_geo` is a reserved keyword and thus can't be used as a sort expression. Use the _geoPoint(latitude, longitude) built-in rule to sort on _geo field coordinates.", - "code": "invalid_sort", + "code": "invalid_search_sort", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-sort" + "link": "https://docs.meilisearch.com/errors#invalid-search-sort" }); index .search( @@ -406,9 +406,9 @@ async fn sort_reserved_attribute() { let expected_response = json!({ "message": "`_geoDistance` is a reserved keyword and thus can't be used as a sort expression.", - "code": "invalid_sort", + "code": "invalid_search_sort", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-sort" + "link": "https://docs.meilisearch.com/errors#invalid-search-sort" }); index .search( @@ -436,9 +436,9 @@ async fn sort_unsortable_attribute() { let expected_response = json!({ "message": "Attribute `title` is not sortable. Available sortable attributes are: `id`.", - "code": "invalid_sort", + "code": "invalid_search_sort", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-sort" + "link": "https://docs.meilisearch.com/errors#invalid-search-sort" }); index .search( @@ -466,9 +466,9 @@ async fn sort_invalid_syntax() { let expected_response = json!({ "message": "Invalid syntax for the sort parameter: expected expression ending by `:asc` or `:desc`, found `title`.", - "code": "invalid_sort", + "code": "invalid_search_sort", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-sort" + "link": "https://docs.meilisearch.com/errors#invalid-search-sort" }); index .search( @@ -500,9 +500,9 @@ async fn sort_unset_ranking_rule() { let expected_response = json!({ "message": "The sort ranking rule must be specified in the ranking rules settings to use the sort parameter at search time.", - "code": "invalid_sort", + "code": "invalid_search_sort", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-sort" + "link": "https://docs.meilisearch.com/errors#invalid-search-sort" }); index .search( diff --git a/meilisearch/tests/settings/get_settings.rs b/meilisearch/tests/settings/get_settings.rs index 0b71dac1c..8ec10db39 100644 --- a/meilisearch/tests/settings/get_settings.rs +++ b/meilisearch/tests/settings/get_settings.rs @@ -288,9 +288,9 @@ async fn error_set_invalid_ranking_rules() { let expected_error = json!({ "message": r#"`manyTheFish` ranking rule is invalid. Valid ranking rules are words, typo, sort, proximity, attribute, exactness and custom ranking rules."#, - "code": "invalid_ranking_rule", + "code": "invalid_settings_ranking_rules", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-ranking-rule" + "link": "https://docs.meilisearch.com/errors#invalid-settings-ranking-rules" }); assert_eq!(response["error"], expected_error); diff --git a/meilisearch/tests/tasks/mod.rs b/meilisearch/tests/tasks/mod.rs index 4505d7fe5..5add71475 100644 --- a/meilisearch/tests/tasks/mod.rs +++ b/meilisearch/tests/tasks/mod.rs @@ -537,9 +537,9 @@ async fn test_summarized_settings_update() { }, "error": { "message": "`custom` ranking rule is invalid. Valid ranking rules are words, typo, sort, proximity, attribute, exactness and custom ranking rules.", - "code": "invalid_ranking_rule", + "code": "invalid_settings_ranking_rules", "type": "invalid_request", - "link": "https://docs.meilisearch.com/errors#invalid-ranking-rule" + "link": "https://docs.meilisearch.com/errors#invalid-settings-ranking-rules" }, "duration": "[duration]", "enqueuedAt": "[date]",