mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
Merge #1878
1878: Add error object in task r=MarinPostma a=ManyTheFish # Pull Request ## What does this PR do? Fixes #1877 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Update error test - [x] Remove flattening of errors during task serialization Co-authored-by: many <maxime@meilisearch.com>
This commit is contained in:
commit
e9b6a05b75
@ -97,8 +97,7 @@ pub struct FailedUpdateResult {
|
||||
pub update_id: u64,
|
||||
#[serde(rename = "type")]
|
||||
pub update_type: UpdateType,
|
||||
#[serde(flatten)]
|
||||
pub response: ResponseError,
|
||||
pub error: ResponseError,
|
||||
pub duration: f64, // in seconds
|
||||
pub enqueued_at: DateTime<Utc>,
|
||||
pub processed_at: DateTime<Utc>,
|
||||
@ -190,12 +189,12 @@ impl From<UpdateStatus> for UpdateStatusResponse {
|
||||
let update_id = failed.id();
|
||||
let processed_at = failed.failed_at;
|
||||
let enqueued_at = failed.from.from.enqueued_at;
|
||||
let response = failed.into();
|
||||
let error = failed.into();
|
||||
|
||||
let content = FailedUpdateResult {
|
||||
update_id,
|
||||
update_type,
|
||||
response,
|
||||
error,
|
||||
duration,
|
||||
enqueued_at,
|
||||
processed_at,
|
||||
|
@ -812,13 +812,15 @@ async fn error_add_documents_bad_document_id() {
|
||||
let (response, code) = index.get_update(0).await;
|
||||
assert_eq!(code, 200);
|
||||
assert_eq!(response["status"], json!("failed"));
|
||||
assert_eq!(response["message"], json!("Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_)."));
|
||||
assert_eq!(response["code"], json!("invalid_document_id"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
json!("https://docs.meilisearch.com/errors#invalid_document_id")
|
||||
);
|
||||
|
||||
let expected_error = json!({
|
||||
"message": "Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).",
|
||||
"code": "invalid_document_id",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#invalid_document_id"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -837,13 +839,15 @@ async fn error_update_documents_bad_document_id() {
|
||||
let (response, code) = index.get_update(0).await;
|
||||
assert_eq!(code, 200);
|
||||
assert_eq!(response["status"], json!("failed"));
|
||||
assert_eq!(response["message"], json!("Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_)."));
|
||||
assert_eq!(response["code"], json!("invalid_document_id"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
json!("https://docs.meilisearch.com/errors#invalid_document_id")
|
||||
);
|
||||
|
||||
let expected_error = json!({
|
||||
"message": "Document identifier `foo & bar` is invalid. A document identifier can be of type integer or string, only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_).",
|
||||
"code": "invalid_document_id",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#invalid_document_id"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -862,16 +866,15 @@ async fn error_add_documents_missing_document_id() {
|
||||
let (response, code) = index.get_update(0).await;
|
||||
assert_eq!(code, 200);
|
||||
assert_eq!(response["status"], "failed");
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
json!(r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#)
|
||||
);
|
||||
assert_eq!(response["code"], json!("missing_document_id"));
|
||||
assert_eq!(response["type"], json!("invalid_request"));
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
json!("https://docs.meilisearch.com/errors#missing_document_id")
|
||||
);
|
||||
|
||||
let expected_error = json!({
|
||||
"message": r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#,
|
||||
"code": "missing_document_id",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#missing_document_id"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -890,16 +893,15 @@ async fn error_update_documents_missing_document_id() {
|
||||
let (response, code) = index.get_update(0).await;
|
||||
assert_eq!(code, 200);
|
||||
assert_eq!(response["status"], "failed");
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#
|
||||
);
|
||||
assert_eq!(response["code"], "missing_document_id");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#missing_document_id"
|
||||
);
|
||||
|
||||
let expected_error = json!({
|
||||
"message": r#"Document doesn't have a `docid` attribute: `{"id":"11","content":"foobar"}`."#,
|
||||
"code": "missing_document_id",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#missing_document_id"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -927,16 +929,15 @@ async fn error_document_field_limit_reached() {
|
||||
assert_eq!(code, 200);
|
||||
// Documents without a primary key are not accepted.
|
||||
assert_eq!(response["status"], "failed");
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
"A document cannot contain more than 65,535 fields."
|
||||
);
|
||||
assert_eq!(response["code"], "document_fields_limit_reached");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#document_fields_limit_reached"
|
||||
);
|
||||
|
||||
let expected_error = json!({
|
||||
"message": "A document cannot contain more than 65,535 fields.",
|
||||
"code": "document_fields_limit_reached",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#document_fields_limit_reached"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -960,16 +961,15 @@ async fn error_add_documents_invalid_geo_field() {
|
||||
let (response, code) = index.get_update(1).await;
|
||||
assert_eq!(code, 200);
|
||||
assert_eq!(response["status"], "failed");
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
r#"The document with the id: `11` contains an invalid _geo field: `foobar`."#
|
||||
);
|
||||
assert_eq!(response["code"], "invalid_geo_field");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#invalid_geo_field"
|
||||
);
|
||||
|
||||
let expected_error = json!({
|
||||
"message": r#"The document with the id: `11` contains an invalid _geo field: `foobar`."#,
|
||||
"code": "invalid_geo_field",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#invalid_geo_field"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
@ -1015,14 +1015,13 @@ async fn error_primary_key_inference() {
|
||||
let (response, code) = index.get_update(0).await;
|
||||
assert_eq!(code, 200);
|
||||
assert_eq!(response["status"], "failed");
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
r#"The primary key inference process failed because the engine did not find any fields containing `id` substring in their name. If your document identifier does not contain any `id` substring, you can set the primary key of the index."#
|
||||
);
|
||||
assert_eq!(response["code"], "primary_key_inference_failed");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#primary_key_inference_failed"
|
||||
);
|
||||
|
||||
let expected_error = json!({
|
||||
"message": r#"The primary key inference process failed because the engine did not find any fields containing `id` substring in their name. If your document identifier does not contain any `id` substring, you can set the primary key of the index."#,
|
||||
"code": "primary_key_inference_failed",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#primary_key_inference_failed"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
@ -279,16 +279,15 @@ async fn error_set_invalid_ranking_rules() {
|
||||
|
||||
assert_eq!(code, 200);
|
||||
assert_eq!(response["status"], "failed");
|
||||
assert_eq!(
|
||||
response["message"],
|
||||
r#"`manyTheFish` ranking rule is invalid. Valid ranking rules are Words, Typo, Sort, Proximity, Attribute, Exactness and custom ranking rules."#
|
||||
);
|
||||
assert_eq!(response["code"], "invalid_ranking_rule");
|
||||
assert_eq!(response["type"], "invalid_request");
|
||||
assert_eq!(
|
||||
response["link"],
|
||||
"https://docs.meilisearch.com/errors#invalid_ranking_rule"
|
||||
);
|
||||
|
||||
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",
|
||||
"type": "invalid_request",
|
||||
"link": "https://docs.meilisearch.com/errors#invalid_ranking_rule"
|
||||
});
|
||||
|
||||
assert_eq!(response["error"], expected_error);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
|
Loading…
Reference in New Issue
Block a user