remove two ununsed error codes + fix the sort error_code

This commit is contained in:
Tamo 2023-01-09 18:59:09 +01:00
parent ff843881c5
commit d308684395
6 changed files with 42 additions and 60 deletions

View File

@ -265,15 +265,15 @@ impl From<v5::ResponseError> for v6::ResponseError {
"max_fields_limit_exceeded" => v6::Code::MaxFieldsLimitExceeded, "max_fields_limit_exceeded" => v6::Code::MaxFieldsLimitExceeded,
"missing_document_id" => v6::Code::MissingDocumentId, "missing_document_id" => v6::Code::MissingDocumentId,
"invalid_document_id" => v6::Code::InvalidDocumentId, "invalid_document_id" => v6::Code::InvalidDocumentId,
"invalid_filter" => v6::Code::Filter, "invalid_filter" => v6::Code::InvalidSettingsFilterableAttributes,
"invalid_sort" => v6::Code::Sort, "invalid_sort" => v6::Code::InvalidSettingsSortableAttributes,
"bad_parameter" => v6::Code::BadParameter, "bad_parameter" => v6::Code::BadParameter,
"bad_request" => v6::Code::BadRequest, "bad_request" => v6::Code::BadRequest,
"database_size_limit_reached" => v6::Code::DatabaseSizeLimitReached, "database_size_limit_reached" => v6::Code::DatabaseSizeLimitReached,
"document_not_found" => v6::Code::DocumentNotFound, "document_not_found" => v6::Code::DocumentNotFound,
"internal" => v6::Code::Internal, "internal" => v6::Code::Internal,
"invalid_geo_field" => v6::Code::InvalidDocumentGeoField, "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_store_file" => v6::Code::InvalidStore,
"invalid_api_key" => v6::Code::InvalidToken, "invalid_api_key" => v6::Code::InvalidToken,
"missing_authorization_header" => v6::Code::MissingAuthorizationHeader, "missing_authorization_header" => v6::Code::MissingAuthorizationHeader,
@ -281,8 +281,7 @@ impl From<v5::ResponseError> for v6::ResponseError {
"dump_not_found" => v6::Code::DumpNotFound, "dump_not_found" => v6::Code::DumpNotFound,
"task_not_found" => v6::Code::TaskNotFound, "task_not_found" => v6::Code::TaskNotFound,
"payload_too_large" => v6::Code::PayloadTooLarge, "payload_too_large" => v6::Code::PayloadTooLarge,
"unretrievable_document" => v6::Code::RetrieveDocument, "unretrievable_document" => v6::Code::DocumentNotFound,
"search_error" => v6::Code::SearchDocuments,
"unsupported_media_type" => v6::Code::UnsupportedMediaType, "unsupported_media_type" => v6::Code::UnsupportedMediaType,
"dump_already_processing" => v6::Code::DumpAlreadyInProgress, "dump_already_processing" => v6::Code::DumpAlreadyInProgress,
"dump_process_failed" => v6::Code::DumpProcessFailed, "dump_process_failed" => v6::Code::DumpProcessFailed,

View File

@ -141,9 +141,6 @@ pub enum Code {
MissingDocumentId, MissingDocumentId,
InvalidDocumentId, InvalidDocumentId,
Filter,
Sort,
// Invalid swap-indexes // Invalid swap-indexes
InvalidSwapIndexes, InvalidSwapIndexes,
InvalidDuplicateIndexesFound, InvalidDuplicateIndexesFound,
@ -205,7 +202,6 @@ pub enum Code {
DocumentNotFound, DocumentNotFound,
Internal, Internal,
InvalidDocumentGeoField, InvalidDocumentGeoField,
InvalidRankingRule,
InvalidStore, InvalidStore,
InvalidToken, InvalidToken,
MissingAuthorizationHeader, MissingAuthorizationHeader,
@ -215,8 +211,6 @@ pub enum Code {
TaskDeletionWithEmptyQuery, TaskDeletionWithEmptyQuery,
TaskCancelationWithEmptyQuery, TaskCancelationWithEmptyQuery,
PayloadTooLarge, PayloadTooLarge,
RetrieveDocument,
SearchDocuments,
UnsupportedMediaType, UnsupportedMediaType,
DumpAlreadyInProgress, DumpAlreadyInProgress,
@ -292,8 +286,6 @@ impl Code {
PrimaryKeyAlreadyPresent => { PrimaryKeyAlreadyPresent => {
ErrCode::invalid("index_primary_key_already_exists", StatusCode::BAD_REQUEST) ErrCode::invalid("index_primary_key_already_exists", StatusCode::BAD_REQUEST)
} }
// invalid ranking rule
InvalidRankingRule => ErrCode::invalid("invalid_ranking_rule", StatusCode::BAD_REQUEST),
// invalid database // invalid database
InvalidStore => { InvalidStore => {
@ -307,11 +299,6 @@ impl Code {
MissingDocumentId => ErrCode::invalid("missing_document_id", StatusCode::BAD_REQUEST), MissingDocumentId => ErrCode::invalid("missing_document_id", StatusCode::BAD_REQUEST),
InvalidDocumentId => ErrCode::invalid("invalid_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), BadParameter => ErrCode::invalid("bad_parameter", StatusCode::BAD_REQUEST),
BadRequest => ErrCode::invalid("bad_request", StatusCode::BAD_REQUEST), BadRequest => ErrCode::invalid("bad_request", StatusCode::BAD_REQUEST),
DatabaseSizeLimitReached => { DatabaseSizeLimitReached => {
@ -338,10 +325,6 @@ impl Code {
} }
DumpNotFound => ErrCode::invalid("dump_not_found", StatusCode::NOT_FOUND), DumpNotFound => ErrCode::invalid("dump_not_found", StatusCode::NOT_FOUND),
PayloadTooLarge => ErrCode::invalid("payload_too_large", StatusCode::PAYLOAD_TOO_LARGE), 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 => { UnsupportedMediaType => {
ErrCode::invalid("unsupported_media_type", StatusCode::UNSUPPORTED_MEDIA_TYPE) ErrCode::invalid("unsupported_media_type", StatusCode::UNSUPPORTED_MEDIA_TYPE)
} }
@ -612,7 +595,7 @@ impl ErrorCode for milli::Error {
UserError::NoSpaceLeftOnDevice => Code::NoSpaceLeftOnDevice, UserError::NoSpaceLeftOnDevice => Code::NoSpaceLeftOnDevice,
UserError::MaxDatabaseSizeReached => Code::DatabaseSizeLimitReached, UserError::MaxDatabaseSizeReached => Code::DatabaseSizeLimitReached,
UserError::AttributeLimitReached => Code::MaxFieldsLimitExceeded, UserError::AttributeLimitReached => Code::MaxFieldsLimitExceeded,
UserError::InvalidFilter(_) => Code::Filter, UserError::InvalidFilter(_) => Code::InvalidSearchFilter,
UserError::MissingDocumentId { .. } => Code::MissingDocumentId, UserError::MissingDocumentId { .. } => Code::MissingDocumentId,
UserError::InvalidDocumentId { .. } | UserError::TooManyDocumentIds { .. } => { UserError::InvalidDocumentId { .. } | UserError::TooManyDocumentIds { .. } => {
Code::InvalidDocumentId Code::InvalidDocumentId
@ -622,12 +605,12 @@ impl ErrorCode for milli::Error {
Code::MultiplePrimaryKeyCandidatesFound Code::MultiplePrimaryKeyCandidatesFound
} }
UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent, UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent,
UserError::SortRankingRuleMissing => Code::Sort, UserError::SortRankingRuleMissing => Code::InvalidSearchSort,
UserError::InvalidFacetsDistribution { .. } => Code::BadRequest, UserError::InvalidFacetsDistribution { .. } => Code::BadRequest,
UserError::InvalidSortableAttribute { .. } => Code::Sort, UserError::InvalidSortableAttribute { .. } => Code::InvalidSearchSort,
UserError::CriterionError(_) => Code::InvalidRankingRule, UserError::CriterionError(_) => Code::InvalidSettingsRankingRules,
UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField, UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField,
UserError::SortError(_) => Code::Sort, UserError::SortError(_) => Code::InvalidSearchSort,
UserError::InvalidMinTypoWordLenSetting(_, _) => { UserError::InvalidMinTypoWordLenSetting(_, _) => {
Code::InvalidMinWordLengthForTypo Code::InvalidMinWordLengthForTypo
} }

View File

@ -55,7 +55,7 @@ impl ErrorCode for MeilisearchHttpError {
MeilisearchHttpError::MissingPayload(_) => Code::MissingPayload, MeilisearchHttpError::MissingPayload(_) => Code::MissingPayload,
MeilisearchHttpError::InvalidContentType(_, _) => Code::InvalidContentType, MeilisearchHttpError::InvalidContentType(_, _) => Code::InvalidContentType,
MeilisearchHttpError::DocumentNotFound(_) => Code::DocumentNotFound, MeilisearchHttpError::DocumentNotFound(_) => Code::DocumentNotFound,
MeilisearchHttpError::InvalidExpression(_, _) => Code::Filter, MeilisearchHttpError::InvalidExpression(_, _) => Code::InvalidSearchFilter,
MeilisearchHttpError::PayloadTooLarge => Code::PayloadTooLarge, MeilisearchHttpError::PayloadTooLarge => Code::PayloadTooLarge,
MeilisearchHttpError::SwapIndexPayloadWrongLength(_) => Code::InvalidSwapIndexes, MeilisearchHttpError::SwapIndexPayloadWrongLength(_) => Code::InvalidSwapIndexes,
MeilisearchHttpError::IndexUid(e) => e.error_code(), MeilisearchHttpError::IndexUid(e) => e.error_code(),

View File

@ -151,9 +151,9 @@ async fn filter_invalid_syntax_object() {
let expected_response = json!({ 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", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": "title & Glass"}), |response, code| { .search(json!({"filter": "title & Glass"}), |response, code| {
@ -176,9 +176,9 @@ async fn filter_invalid_syntax_array() {
let expected_response = json!({ 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", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": ["title & Glass"]}), |response, code| { .search(json!({"filter": ["title & Glass"]}), |response, code| {
@ -201,9 +201,9 @@ async fn filter_invalid_syntax_string() {
let expected_response = json!({ 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", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": "title = Glass XOR title = Glass"}), |response, code| { .search(json!({"filter": "title = Glass XOR title = Glass"}), |response, code| {
@ -226,9 +226,9 @@ async fn filter_invalid_attribute_array() {
let expected_response = json!({ let expected_response = json!({
"message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": ["many = Glass"]}), |response, code| { .search(json!({"filter": ["many = Glass"]}), |response, code| {
@ -251,9 +251,9 @@ async fn filter_invalid_attribute_string() {
let expected_response = json!({ let expected_response = json!({
"message": "Attribute `many` is not filterable. Available filterable attributes are: `title`.\n1:5 many = Glass", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": "many = Glass"}), |response, code| { .search(json!({"filter": "many = Glass"}), |response, code| {
@ -276,9 +276,9 @@ async fn filter_reserved_geo_attribute_array() {
let expected_response = json!({ 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", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": ["_geo = Glass"]}), |response, code| { .search(json!({"filter": ["_geo = Glass"]}), |response, code| {
@ -301,9 +301,9 @@ async fn filter_reserved_geo_attribute_string() {
let expected_response = json!({ 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", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": "_geo = Glass"}), |response, code| { .search(json!({"filter": "_geo = Glass"}), |response, code| {
@ -326,9 +326,9 @@ async fn filter_reserved_attribute_array() {
let expected_response = json!({ let expected_response = json!({
"message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression.\n1:13 _geoDistance = Glass", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": ["_geoDistance = Glass"]}), |response, code| { .search(json!({"filter": ["_geoDistance = Glass"]}), |response, code| {
@ -351,9 +351,9 @@ async fn filter_reserved_attribute_string() {
let expected_response = json!({ let expected_response = json!({
"message": "`_geoDistance` is a reserved keyword and thus can't be used as a filter expression.\n1:13 _geoDistance = Glass", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-filter" "link": "https://docs.meilisearch.com/errors#invalid-search-filter"
}); });
index index
.search(json!({"filter": "_geoDistance = Glass"}), |response, code| { .search(json!({"filter": "_geoDistance = Glass"}), |response, code| {
@ -376,9 +376,9 @@ async fn sort_geo_reserved_attribute() {
let expected_response = json!({ 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.", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-sort" "link": "https://docs.meilisearch.com/errors#invalid-search-sort"
}); });
index index
.search( .search(
@ -406,9 +406,9 @@ async fn sort_reserved_attribute() {
let expected_response = json!({ let expected_response = json!({
"message": "`_geoDistance` is a reserved keyword and thus can't be used as a sort expression.", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-sort" "link": "https://docs.meilisearch.com/errors#invalid-search-sort"
}); });
index index
.search( .search(
@ -436,9 +436,9 @@ async fn sort_unsortable_attribute() {
let expected_response = json!({ let expected_response = json!({
"message": "Attribute `title` is not sortable. Available sortable attributes are: `id`.", "message": "Attribute `title` is not sortable. Available sortable attributes are: `id`.",
"code": "invalid_sort", "code": "invalid_search_sort",
"type": "invalid_request", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-sort" "link": "https://docs.meilisearch.com/errors#invalid-search-sort"
}); });
index index
.search( .search(
@ -466,9 +466,9 @@ async fn sort_invalid_syntax() {
let expected_response = json!({ let expected_response = json!({
"message": "Invalid syntax for the sort parameter: expected expression ending by `:asc` or `:desc`, found `title`.", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-sort" "link": "https://docs.meilisearch.com/errors#invalid-search-sort"
}); });
index index
.search( .search(
@ -500,9 +500,9 @@ async fn sort_unset_ranking_rule() {
let expected_response = json!({ 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.", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-sort" "link": "https://docs.meilisearch.com/errors#invalid-search-sort"
}); });
index index
.search( .search(

View File

@ -288,9 +288,9 @@ async fn error_set_invalid_ranking_rules() {
let expected_error = json!({ 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."#, "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", "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); assert_eq!(response["error"], expected_error);

View File

@ -537,9 +537,9 @@ async fn test_summarized_settings_update() {
}, },
"error": { "error": {
"message": "`custom` ranking rule is invalid. Valid ranking rules are words, typo, sort, proximity, attribute, exactness and custom ranking rules.", "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", "type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid-ranking-rule" "link": "https://docs.meilisearch.com/errors#invalid-settings-ranking-rules"
}, },
"duration": "[duration]", "duration": "[duration]",
"enqueuedAt": "[date]", "enqueuedAt": "[date]",