bump enum-iter and fix a bunch of error messages

This commit is contained in:
Tamo 2022-10-17 18:57:23 +02:00 committed by Clément Renault
parent bea81ae37b
commit d1a6fb2971
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
7 changed files with 275 additions and 212 deletions

394
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@ version = "0.29.1"
edition = "2021"
[dependencies]
enum-iterator = "1.1.2"
enum-iterator = "1.1.3"
hmac = "0.12.1"
meilisearch-types = { path = "../meilisearch-types" }
rand = "0.8.5"

View File

@ -1,7 +1,7 @@
use std::error::Error;
use meilisearch_types::error::{Code, ErrorCode};
use meilisearch_types::{internal_error, keys, milli};
use meilisearch_types::{internal_error, keys};
pub type Result<T> = std::result::Result<T, AuthControllerError>;

View File

@ -13,7 +13,6 @@ use hmac::{Hmac, Mac};
use meilisearch_types::keys::KeyId;
use meilisearch_types::milli;
use meilisearch_types::star_or::StarOr;
use meilisearch_types::milli;
use milli::heed::types::{ByteSlice, DecodeIgnore, SerdeJson};
use milli::heed::{Database, Env, EnvOpenOptions, RwTxn};
use sha2::Sha256;

View File

@ -9,7 +9,7 @@ actix-web = { version = "4.2.1", default-features = false }
csv = "1.1.6"
either = { version = "1.6.1", features = ["serde"] }
milli = { git = "https://github.com/meilisearch/milli.git", branch = "indexation-abortion", default-features = false }
enum-iterator = "0.7.0"
enum-iterator = "1.1.3"
fst = "0.4.7"
proptest = { version = "1.0.0", optional = true }
proptest-derive = { version = "0.3.0", optional = true }

View File

@ -1,7 +1,7 @@
use crate::error::{Code, ErrorCode};
use crate::index_uid::IndexUid;
use crate::star_or::StarOr;
use enum_iterator::IntoEnumIterator;
use enum_iterator::Sequence;
use serde::{Deserialize, Serialize};
use serde_json::{from_value, Value};
use std::hash::Hash;
@ -197,7 +197,7 @@ fn parse_expiration_date(value: &Value) -> Result<Option<OffsetDateTime>> {
}
}
#[derive(IntoEnumIterator, Copy, Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Hash)]
#[derive(Copy, Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Sequence)]
#[repr(u8)]
pub enum Action {
#[serde(rename = "*")]

View File

@ -1,3 +1,4 @@
use enum_iterator::Sequence;
use milli::update::IndexDocumentsMethod;
use roaring::RoaringBitmap;
use serde::{Deserialize, Serialize, Serializer};
@ -263,7 +264,7 @@ impl From<&KindWithContent> for Option<Details> {
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Sequence)]
#[serde(rename_all = "camelCase")]
pub enum Status {
Enqueued,
@ -286,21 +287,32 @@ impl Display for Status {
impl FromStr for Status {
type Err = ResponseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"enqueued" => Ok(Status::Enqueued),
"processing" => Ok(Status::Processing),
"succeeded" => Ok(Status::Succeeded),
"failed" => Ok(Status::Failed),
s => Err(ResponseError::from_msg(
format!("`{}` is not a status. Available types are", s),
fn from_str(status: &str) -> Result<Self, Self::Err> {
if status.eq_ignore_ascii_case("enqueued") {
Ok(Status::Enqueued)
} else if status.eq_ignore_ascii_case("processing") {
Ok(Status::Processing)
} else if status.eq_ignore_ascii_case("succeeded") {
Ok(Status::Succeeded)
} else if status.eq_ignore_ascii_case("failed") {
Ok(Status::Failed)
} else {
Err(ResponseError::from_msg(
format!(
"`{}` is not a status. Available status are {}.",
status,
enum_iterator::all::<Status>()
.map(|s| format!("`{s}`"))
.collect::<Vec<String>>()
.join(", ")
),
Code::BadRequest,
)),
))
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Sequence)]
#[serde(rename_all = "camelCase")]
pub enum Kind {
DocumentImport,
@ -320,25 +332,37 @@ pub enum Kind {
impl FromStr for Kind {
type Err = ResponseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"document_addition" => Ok(Kind::DocumentImport),
"document_update" => Ok(Kind::DocumentImport),
"document_deletion" => Ok(Kind::DocumentDeletion),
"document_clear" => Ok(Kind::DocumentClear),
"settings" => Ok(Kind::Settings),
"index_creation" => Ok(Kind::IndexCreation),
"index_deletion" => Ok(Kind::IndexDeletion),
"index_update" => Ok(Kind::IndexUpdate),
"index_swap" => Ok(Kind::IndexSwap),
"cancel_task" => Ok(Kind::CancelTask),
"task_deletion" => Ok(Kind::TaskDeletion),
"dump_export" => Ok(Kind::DumpExport),
"snapshot" => Ok(Kind::Snapshot),
s => Err(ResponseError::from_msg(
format!("`{}` is not a type. Available status are ", s),
fn from_str(kind: &str) -> Result<Self, Self::Err> {
if kind.eq_ignore_ascii_case("indexCreation") {
Ok(Kind::IndexCreation)
} else if kind.eq_ignore_ascii_case("indexUpdate") {
Ok(Kind::IndexUpdate)
} else if kind.eq_ignore_ascii_case("indexDeletion") {
Ok(Kind::IndexDeletion)
} else if kind.eq_ignore_ascii_case("documentAdditionOrUpdate") {
Ok(Kind::DocumentImport)
} else if kind.eq_ignore_ascii_case("documentDeletion") {
Ok(Kind::DocumentDeletion)
} else if kind.eq_ignore_ascii_case("settingsUpdate") {
Ok(Kind::Settings)
} else if kind.eq_ignore_ascii_case("dumpCreation") {
Ok(Kind::DumpExport)
} else {
Err(ResponseError::from_msg(
format!(
"`{}` is not a type. Available types are {}.",
kind,
enum_iterator::all::<Kind>()
.map(|k| format!(
"`{}`",
// by default serde is going to insert `"` around the value.
serde_json::to_string(&k).unwrap().trim_matches('"')
))
.collect::<Vec<String>>()
.join(", ")
),
Code::BadRequest,
)),
))
}
}
}