mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
Update deserr to latest version + add new error codes for missing fields
- missing_api_key_indexes - missing_api_key_actions - missing_api_key_expires_at - missing_swap_indexes_indexes
This commit is contained in:
parent
436ae4e466
commit
766dd830ae
16 changed files with 158 additions and 128 deletions
|
@ -9,14 +9,14 @@ actix-web = { version = "4.2.1", default-features = false }
|
|||
anyhow = "1.0.65"
|
||||
convert_case = "0.6.0"
|
||||
csv = "1.1.6"
|
||||
deserr = "0.1.4"
|
||||
deserr = { path = "/Users/meilisearch/Documents/deserr" }
|
||||
either = { version = "1.6.1", features = ["serde"] }
|
||||
enum-iterator = "1.1.3"
|
||||
file-store = { path = "../file-store" }
|
||||
flate2 = "1.0.24"
|
||||
fst = "0.4.7"
|
||||
memmap2 = "0.5.7"
|
||||
milli = { git = "https://github.com/meilisearch/milli.git", tag = "v0.39.0", default-features = false }
|
||||
milli = { path = "/Users/meilisearch/Documents/milli2/milli", default-features = false }
|
||||
proptest = { version = "1.0.0", optional = true }
|
||||
proptest-derive = { version = "0.3.0", optional = true }
|
||||
roaring = { version = "0.10.0", features = ["serde"] }
|
||||
|
|
|
@ -14,7 +14,9 @@ use serde_cs::vec::CS;
|
|||
|
||||
use crate::star_or::StarOr;
|
||||
|
||||
use self::deserr_codes::MissingIndexUid;
|
||||
use self::deserr_codes::{
|
||||
MissingApiKeyActions, MissingApiKeyExpiresAt, MissingApiKeyIndexes, MissingIndexUid, InvalidSwapIndexes, MissingSwapIndexesIndexes,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -185,7 +187,6 @@ DumpAlreadyProcessing , invalid , CONFLICT;
|
|||
DumpNotFound , invalid , NOT_FOUND;
|
||||
DumpProcessFailed , internal , INTERNAL_SERVER_ERROR;
|
||||
DuplicateIndexFound , invalid , BAD_REQUEST;
|
||||
|
||||
ImmutableApiKeyUid , invalid , BAD_REQUEST;
|
||||
ImmutableApiKeyKey , invalid , BAD_REQUEST;
|
||||
ImmutableApiKeyActions , invalid , BAD_REQUEST;
|
||||
|
@ -193,11 +194,9 @@ ImmutableApiKeyIndexes , invalid , BAD_REQUEST;
|
|||
ImmutableApiKeyExpiresAt , invalid , BAD_REQUEST;
|
||||
ImmutableApiKeyCreatedAt , invalid , BAD_REQUEST;
|
||||
ImmutableApiKeyUpdatedAt , invalid , BAD_REQUEST;
|
||||
|
||||
ImmutableIndexUid , invalid , BAD_REQUEST;
|
||||
ImmutableIndexCreatedAt , invalid , BAD_REQUEST;
|
||||
ImmutableIndexUpdatedAt , invalid , BAD_REQUEST;
|
||||
|
||||
IndexAlreadyExists , invalid , CONFLICT ;
|
||||
IndexCreationFailed , internal , INTERNAL_SERVER_ERROR;
|
||||
IndexNotFound , invalid , NOT_FOUND;
|
||||
|
@ -281,6 +280,7 @@ MissingDocumentId , invalid , BAD_REQUEST ;
|
|||
MissingIndexUid , invalid , BAD_REQUEST ;
|
||||
MissingMasterKey , authentication, UNAUTHORIZED ;
|
||||
MissingPayload , invalid , BAD_REQUEST ;
|
||||
MissingSwapIndexesIndexes , invalid , BAD_REQUEST ;
|
||||
MissingTaskFilters , invalid , BAD_REQUEST ;
|
||||
NoSpaceLeftOnDevice , system , UNPROCESSABLE_ENTITY;
|
||||
PayloadTooLarge , invalid , PAYLOAD_TOO_LARGE ;
|
||||
|
@ -478,6 +478,47 @@ impl DeserrJsonError<MissingIndexUid> {
|
|||
Self { msg: x.msg, code: MissingIndexUid.error_code(), _phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
impl DeserrJsonError<MissingApiKeyActions> {
|
||||
pub fn missing_api_key_actions(field: &str, location: ValuePointerRef) -> Self {
|
||||
let x = unwrap_any(Self::error::<Infallible>(
|
||||
None,
|
||||
deserr::ErrorKind::MissingField { field },
|
||||
location,
|
||||
));
|
||||
Self { msg: x.msg, code: MissingApiKeyActions.error_code(), _phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
impl DeserrJsonError<MissingApiKeyExpiresAt> {
|
||||
pub fn missing_api_key_expires_at(field: &str, location: ValuePointerRef) -> Self {
|
||||
let x = unwrap_any(Self::error::<Infallible>(
|
||||
None,
|
||||
deserr::ErrorKind::MissingField { field },
|
||||
location,
|
||||
));
|
||||
Self { msg: x.msg, code: MissingApiKeyExpiresAt.error_code(), _phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
impl DeserrJsonError<MissingApiKeyIndexes> {
|
||||
pub fn missing_api_key_indexes(field: &str, location: ValuePointerRef) -> Self {
|
||||
let x = unwrap_any(Self::error::<Infallible>(
|
||||
None,
|
||||
deserr::ErrorKind::MissingField { field },
|
||||
location,
|
||||
));
|
||||
Self { msg: x.msg, code: MissingApiKeyIndexes.error_code(), _phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl DeserrJsonError<InvalidSwapIndexes> {
|
||||
pub fn missing_swap_indexes_indexes(field: &str, location: ValuePointerRef) -> Self {
|
||||
let x = unwrap_any(Self::error::<Infallible>(
|
||||
None,
|
||||
deserr::ErrorKind::MissingField { field },
|
||||
location,
|
||||
));
|
||||
Self { msg: x.msg, code: MissingSwapIndexesIndexes.error_code(), _phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
// if the error happened in the root, then an empty string is returned.
|
||||
pub fn location_json_description(location: ValuePointerRef, article: &str) -> String {
|
||||
|
|
|
@ -38,17 +38,17 @@ fn parse_uuid_from_str(s: &str) -> Result<Uuid, TakeErrorMessage<uuid::Error>> {
|
|||
#[derive(Debug, DeserializeFromValue)]
|
||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||
pub struct CreateApiKey {
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyDescription>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyDescription>)]
|
||||
pub description: Option<String>,
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyName>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyName>)]
|
||||
pub name: Option<String>,
|
||||
#[deserr(default = Uuid::new_v4(), error = DeserrJsonError<InvalidApiKeyUid>, from(&String) = parse_uuid_from_str -> TakeErrorMessage<uuid::Error>)]
|
||||
pub uid: KeyId,
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyActions>)]
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyActions>, missing_field_error = DeserrJsonError::missing_api_key_actions)]
|
||||
pub actions: Vec<Action>,
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyIndexes>)]
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyIndexes>, missing_field_error = DeserrJsonError::missing_api_key_indexes)]
|
||||
pub indexes: Vec<StarOr<IndexUid>>,
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyExpiresAt>, default = None, from(&String) = parse_expiration_date -> TakeErrorMessage<ParseOffsetDateTimeError>)]
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyExpiresAt>, from(&String) = parse_expiration_date -> TakeErrorMessage<ParseOffsetDateTimeError>, missing_field_error = DeserrJsonError::missing_api_key_expires_at)]
|
||||
pub expires_at: Option<OffsetDateTime>,
|
||||
}
|
||||
impl CreateApiKey {
|
||||
|
@ -94,9 +94,9 @@ fn deny_immutable_fields_api_key(
|
|||
#[derive(Debug, DeserializeFromValue)]
|
||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_api_key)]
|
||||
pub struct PatchApiKey {
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyDescription>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyDescription>)]
|
||||
pub description: Option<String>,
|
||||
#[deserr(error = DeserrJsonError<InvalidApiKeyName>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyName>)]
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ pub mod star_or;
|
|||
pub mod tasks;
|
||||
pub mod versioning;
|
||||
|
||||
pub use deserr;
|
||||
pub use milli;
|
||||
pub use milli::{heed, Index};
|
||||
pub use serde_cs;
|
||||
|
|
|
@ -69,8 +69,10 @@ fn validate_min_word_size_for_typo_setting<E: DeserializeError>(
|
|||
#[deserr(deny_unknown_fields, rename_all = camelCase, validate = validate_min_word_size_for_typo_setting -> DeserrJsonError<InvalidMinWordLengthForTypo>)]
|
||||
pub struct MinWordSizeTyposSetting {
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(default)]
|
||||
pub one_typo: Setting<u8>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(default)]
|
||||
pub two_typos: Setting<u8>,
|
||||
}
|
||||
|
||||
|
@ -79,13 +81,16 @@ pub struct MinWordSizeTyposSetting {
|
|||
#[deserr(deny_unknown_fields, rename_all = camelCase, where_predicate = __Deserr_E: deserr::MergeWithError<DeserrJsonError<InvalidMinWordLengthForTypo>>)]
|
||||
pub struct TypoSettings {
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(default)]
|
||||
pub enabled: Setting<bool>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidMinWordLengthForTypo>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidMinWordLengthForTypo>)]
|
||||
pub min_word_size_for_typos: Setting<MinWordSizeTyposSetting>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(default)]
|
||||
pub disable_on_words: Setting<BTreeSet<String>>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(default)]
|
||||
pub disable_on_attributes: Setting<BTreeSet<String>>,
|
||||
}
|
||||
|
||||
|
@ -94,6 +99,7 @@ pub struct TypoSettings {
|
|||
#[deserr(rename_all = camelCase, deny_unknown_fields)]
|
||||
pub struct FacetingSettings {
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(default)]
|
||||
pub max_values_per_facet: Setting<usize>,
|
||||
}
|
||||
|
||||
|
@ -102,6 +108,7 @@ pub struct FacetingSettings {
|
|||
#[deserr(rename_all = camelCase, deny_unknown_fields)]
|
||||
pub struct PaginationSettings {
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(default)]
|
||||
pub max_total_hits: Setting<usize>,
|
||||
}
|
||||
|
||||
|
@ -135,7 +142,7 @@ pub struct Settings<T> {
|
|||
serialize_with = "serialize_with_wildcard",
|
||||
skip_serializing_if = "Setting::is_not_set"
|
||||
)]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsDisplayedAttributes>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsDisplayedAttributes>)]
|
||||
pub displayed_attributes: Setting<Vec<String>>,
|
||||
|
||||
#[serde(
|
||||
|
@ -143,35 +150,35 @@ pub struct Settings<T> {
|
|||
serialize_with = "serialize_with_wildcard",
|
||||
skip_serializing_if = "Setting::is_not_set"
|
||||
)]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsSearchableAttributes>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsSearchableAttributes>)]
|
||||
pub searchable_attributes: Setting<Vec<String>>,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsFilterableAttributes>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsFilterableAttributes>)]
|
||||
pub filterable_attributes: Setting<BTreeSet<String>>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsSortableAttributes>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsSortableAttributes>)]
|
||||
pub sortable_attributes: Setting<BTreeSet<String>>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsRankingRules>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsRankingRules>)]
|
||||
pub ranking_rules: Setting<Vec<RankingRuleView>>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsStopWords>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsStopWords>)]
|
||||
pub stop_words: Setting<BTreeSet<String>>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsSynonyms>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsSynonyms>)]
|
||||
pub synonyms: Setting<BTreeMap<String, Vec<String>>>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsDistinctAttribute>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsDistinctAttribute>)]
|
||||
pub distinct_attribute: Setting<String>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsTypoTolerance>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsTypoTolerance>)]
|
||||
pub typo_tolerance: Setting<TypoSettings>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsFaceting>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsFaceting>)]
|
||||
pub faceting: Setting<FacetingSettings>,
|
||||
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
||||
#[deserr(error = DeserrJsonError<InvalidSettingsPagination>)]
|
||||
#[deserr(default, error = DeserrJsonError<InvalidSettingsPagination>)]
|
||||
pub pagination: Setting<PaginationSettings>,
|
||||
|
||||
#[serde(skip)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue