mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
get rids of the unwrap_any function in favor of take_cf_content
This commit is contained in:
parent
a43765d454
commit
42a3cdca66
@ -8,7 +8,7 @@ use deserr::{take_cf_content, DeserializeError, IntoValue, MergeWithError, Value
|
|||||||
|
|
||||||
use crate::error::deserr_codes::*;
|
use crate::error::deserr_codes::*;
|
||||||
use crate::error::{
|
use crate::error::{
|
||||||
unwrap_any, Code, DeserrParseBoolError, DeserrParseIntError, ErrorCode, InvalidTaskDateError,
|
Code, DeserrParseBoolError, DeserrParseIntError, ErrorCode, InvalidTaskDateError,
|
||||||
ParseOffsetDateTimeError,
|
ParseOffsetDateTimeError,
|
||||||
};
|
};
|
||||||
use crate::index_uid::IndexUidFormatError;
|
use crate::index_uid::IndexUidFormatError;
|
||||||
@ -135,7 +135,7 @@ macro_rules! make_missing_field_convenience_builder {
|
|||||||
($err_code:ident, $fn_name:ident) => {
|
($err_code:ident, $fn_name:ident) => {
|
||||||
impl DeserrJsonError<$err_code> {
|
impl DeserrJsonError<$err_code> {
|
||||||
pub fn $fn_name(field: &str, location: ValuePointerRef) -> Self {
|
pub fn $fn_name(field: &str, location: ValuePointerRef) -> Self {
|
||||||
let x = unwrap_any(Self::error::<Infallible>(
|
let x = deserr::take_cf_content(Self::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::MissingField { field },
|
deserr::ErrorKind::MissingField { field },
|
||||||
location,
|
location,
|
||||||
|
@ -18,7 +18,6 @@ use std::str::FromStr;
|
|||||||
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
|
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
|
||||||
|
|
||||||
use super::{DeserrParseBoolError, DeserrParseIntError};
|
use super::{DeserrParseBoolError, DeserrParseIntError};
|
||||||
use crate::error::unwrap_any;
|
|
||||||
use crate::index_uid::IndexUid;
|
use crate::index_uid::IndexUid;
|
||||||
use crate::tasks::{Kind, Status};
|
use crate::tasks::{Kind, Status};
|
||||||
|
|
||||||
@ -50,9 +49,9 @@ where
|
|||||||
match value {
|
match value {
|
||||||
deserr::Value::String(s) => match T::from_query_param(&s) {
|
deserr::Value::String(s) => match T::from_query_param(&s) {
|
||||||
Ok(x) => Ok(Param(x)),
|
Ok(x) => Ok(Param(x)),
|
||||||
Err(e) => Err(unwrap_any(E::merge(None, e, location))),
|
Err(e) => Err(deserr::take_cf_content(E::merge(None, e, location))),
|
||||||
},
|
},
|
||||||
_ => Err(unwrap_any(E::error(
|
_ => Err(deserr::take_cf_content(E::error(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
|
@ -381,16 +381,6 @@ impl ErrorCode for io::Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unwrap a result, either its Ok or Err value.
|
|
||||||
pub fn unwrap_any<T>(any: std::ops::ControlFlow<T, T>) -> T {
|
|
||||||
use std::ops::ControlFlow::*;
|
|
||||||
|
|
||||||
match any {
|
|
||||||
Continue(any) => any,
|
|
||||||
Break(any) => any,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deserialization when `deserr` cannot parse an API key date.
|
/// Deserialization when `deserr` cannot parse an API key date.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ParseOffsetDateTimeError(pub String);
|
pub struct ParseOffsetDateTimeError(pub String);
|
||||||
|
@ -13,7 +13,7 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use crate::deserr::{immutable_field_error, DeserrError, DeserrJsonError};
|
use crate::deserr::{immutable_field_error, DeserrError, DeserrJsonError};
|
||||||
use crate::error::deserr_codes::*;
|
use crate::error::deserr_codes::*;
|
||||||
use crate::error::{unwrap_any, Code, ErrorCode, ParseOffsetDateTimeError};
|
use crate::error::{Code, ErrorCode, ParseOffsetDateTimeError};
|
||||||
use crate::index_uid_pattern::{IndexUidPattern, IndexUidPatternFormatError};
|
use crate::index_uid_pattern::{IndexUidPattern, IndexUidPatternFormatError};
|
||||||
|
|
||||||
pub type KeyId = Uuid;
|
pub type KeyId = Uuid;
|
||||||
@ -78,7 +78,7 @@ fn deny_immutable_fields_api_key(
|
|||||||
"expiresAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyExpiresAt),
|
"expiresAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyExpiresAt),
|
||||||
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyCreatedAt),
|
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyCreatedAt),
|
||||||
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyUpdatedAt),
|
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyUpdatedAt),
|
||||||
_ => unwrap_any(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
_ => deserr::take_cf_content(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
||||||
location,
|
location,
|
||||||
|
@ -14,7 +14,6 @@ use serde::{Deserialize, Serialize, Serializer};
|
|||||||
|
|
||||||
use crate::deserr::DeserrJsonError;
|
use crate::deserr::DeserrJsonError;
|
||||||
use crate::error::deserr_codes::*;
|
use crate::error::deserr_codes::*;
|
||||||
use crate::error::unwrap_any;
|
|
||||||
|
|
||||||
/// The maximimum number of results that the engine
|
/// The maximimum number of results that the engine
|
||||||
/// will be able to return in one search call.
|
/// will be able to return in one search call.
|
||||||
@ -60,7 +59,7 @@ fn validate_min_word_size_for_typo_setting<E: DeserializeError>(
|
|||||||
) -> Result<MinWordSizeTyposSetting, E> {
|
) -> Result<MinWordSizeTyposSetting, E> {
|
||||||
if let (Setting::Set(one), Setting::Set(two)) = (s.one_typo, s.two_typos) {
|
if let (Setting::Set(one), Setting::Set(two)) = (s.one_typo, s.two_typos) {
|
||||||
if one > two {
|
if one > two {
|
||||||
return Err(unwrap_any(E::error::<Infallible>(None, ErrorKind::Unexpected { msg: format!("`minWordSizeForTypos` setting is invalid. `oneTypo` and `twoTypos` fields should be between `0` and `255`, and `twoTypos` should be greater or equals to `oneTypo` but found `oneTypo: {one}` and twoTypos: {two}`.") }, location)));
|
return Err(deserr::take_cf_content(E::error::<Infallible>(None, ErrorKind::Unexpected { msg: format!("`minWordSizeForTypos` setting is invalid. `oneTypo` and `twoTypos` fields should be between `0` and `255`, and `twoTypos` should be greater or equals to `oneTypo` but found `oneTypo: {one}` and twoTypos: {two}`.") }, location)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(s)
|
Ok(s)
|
||||||
|
@ -8,7 +8,6 @@ use serde::de::Visitor;
|
|||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
use crate::deserr::query_params::FromQueryParameter;
|
use crate::deserr::query_params::FromQueryParameter;
|
||||||
use crate::error::unwrap_any;
|
|
||||||
|
|
||||||
/// A type that tries to match either a star (*) or
|
/// A type that tries to match either a star (*) or
|
||||||
/// any other thing that implements `FromStr`.
|
/// any other thing that implements `FromStr`.
|
||||||
@ -128,11 +127,11 @@ where
|
|||||||
} else {
|
} else {
|
||||||
match T::from_str(&v) {
|
match T::from_str(&v) {
|
||||||
Ok(parsed) => Ok(StarOr::Other(parsed)),
|
Ok(parsed) => Ok(StarOr::Other(parsed)),
|
||||||
Err(e) => Err(unwrap_any(E::merge(None, e, location))),
|
Err(e) => Err(deserr::take_cf_content(E::merge(None, e, location))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(unwrap_any(E::error::<V>(
|
_ => Err(deserr::take_cf_content(E::error::<V>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
@ -206,10 +205,10 @@ where
|
|||||||
"*" => Ok(OptionStarOr::Star),
|
"*" => Ok(OptionStarOr::Star),
|
||||||
s => match T::from_query_param(s) {
|
s => match T::from_query_param(s) {
|
||||||
Ok(x) => Ok(OptionStarOr::Other(x)),
|
Ok(x) => Ok(OptionStarOr::Other(x)),
|
||||||
Err(e) => Err(unwrap_any(E::merge(None, e, location))),
|
Err(e) => Err(deserr::take_cf_content(E::merge(None, e, location))),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_ => Err(unwrap_any(E::error::<V>(
|
_ => Err(deserr::take_cf_content(E::error::<V>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
@ -318,7 +317,7 @@ where
|
|||||||
Ok(OptionStarOrList::List(els))
|
Ok(OptionStarOrList::List(els))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(unwrap_any(E::error::<V>(
|
_ => Err(deserr::take_cf_content(E::error::<V>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
|
@ -9,7 +9,7 @@ use log::debug;
|
|||||||
use meilisearch_types::deserr::query_params::Param;
|
use meilisearch_types::deserr::query_params::Param;
|
||||||
use meilisearch_types::deserr::{immutable_field_error, DeserrJsonError, DeserrQueryParamError};
|
use meilisearch_types::deserr::{immutable_field_error, DeserrJsonError, DeserrQueryParamError};
|
||||||
use meilisearch_types::error::deserr_codes::*;
|
use meilisearch_types::error::deserr_codes::*;
|
||||||
use meilisearch_types::error::{unwrap_any, Code, ResponseError};
|
use meilisearch_types::error::{Code, ResponseError};
|
||||||
use meilisearch_types::index_uid::IndexUid;
|
use meilisearch_types::index_uid::IndexUid;
|
||||||
use meilisearch_types::milli::{self, FieldDistribution, Index};
|
use meilisearch_types::milli::{self, FieldDistribution, Index};
|
||||||
use meilisearch_types::tasks::KindWithContent;
|
use meilisearch_types::tasks::KindWithContent;
|
||||||
@ -147,7 +147,7 @@ fn deny_immutable_fields_index(
|
|||||||
"uid" => immutable_field_error(field, accepted, Code::ImmutableIndexUid),
|
"uid" => immutable_field_error(field, accepted, Code::ImmutableIndexUid),
|
||||||
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableIndexCreatedAt),
|
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableIndexCreatedAt),
|
||||||
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableIndexUpdatedAt),
|
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableIndexUpdatedAt),
|
||||||
_ => unwrap_any(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
_ => deserr::take_cf_content(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
||||||
location,
|
location,
|
||||||
|
Loading…
Reference in New Issue
Block a user