Apply review suggestions

This commit is contained in:
Loïc Lecrenier 2023-01-11 14:31:34 +01:00 committed by Tamo
parent c91ffec72e
commit b0b7ad7caf
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
12 changed files with 236 additions and 251 deletions

View file

@ -9,7 +9,7 @@ actix-web = { version = "4.2.1", default-features = false }
anyhow = "1.0.65"
convert_case = "0.6.0"
csv = "1.1.6"
deserr = { path = "/Users/meilisearch/Documents/deserr", features = ["serde-json"] }
deserr = { version = "0.1.4", features = ["serde-json"] }
either = { version = "1.6.1", features = ["serde"] }
enum-iterator = "1.1.3"
file-store = { path = "../file-store" }

View file

@ -118,7 +118,6 @@ impl fmt::Display for ErrorType {
macro_rules! make_error_codes {
($($code_ident:ident, $err_type:ident, $status:ident);*) => {
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Code {
$($code_ident),*
@ -210,7 +209,6 @@ InvalidIndexOffset , invalid , BAD_REQUEST ;
InvalidIndexPrimaryKey , invalid , BAD_REQUEST ;
InvalidIndexUid , invalid , BAD_REQUEST ;
InvalidMinWordLengthForTypo , invalid , BAD_REQUEST ;
InvalidRankingRule , invalid , BAD_REQUEST ;
InvalidSearchAttributesToCrop , invalid , BAD_REQUEST ;
InvalidSearchAttributesToHighlight , invalid , BAD_REQUEST ;
InvalidSearchAttributesToRetrieve , invalid , BAD_REQUEST ;
@ -340,7 +338,7 @@ impl ErrorCode for milli::Error {
UserError::SortRankingRuleMissing => Code::InvalidSearchSort,
UserError::InvalidFacetsDistribution { .. } => Code::BadRequest,
UserError::InvalidSortableAttribute { .. } => Code::InvalidSearchSort,
UserError::CriterionError(_) => Code::InvalidRankingRule,
UserError::CriterionError(_) => Code::InvalidSettingsRankingRules,
UserError::InvalidGeoField { .. } => Code::InvalidDocumentGeoField,
UserError::SortError(_) => Code::InvalidSearchSort,
UserError::InvalidMinTypoWordLenSetting(_, _) => {

View file

@ -2,7 +2,7 @@ use std::convert::Infallible;
use std::fmt::Display;
use std::hash::Hash;
use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValueKind, ValuePointerRef};
use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValuePointerRef};
use enum_iterator::Sequence;
use serde::{Deserialize, Serialize};
use time::format_description::well_known::Rfc3339;
@ -17,31 +17,6 @@ use crate::star_or::StarOr;
pub type KeyId = Uuid;
impl<C: Default + ErrorCode> DeserializeFromValue<DeserrError<C>> for Uuid {
fn deserialize_from_value<V: deserr::IntoValue>(
value: deserr::Value<V>,
location: deserr::ValuePointerRef,
) -> std::result::Result<Self, DeserrError<C>> {
match value {
deserr::Value::String(s) => match Uuid::parse_str(&s) {
Ok(x) => Ok(x),
Err(e) => Err(unwrap_any(DeserrError::<C>::error::<V>(
None,
deserr::ErrorKind::Unexpected { msg: e.to_string() },
location,
))),
},
_ => Err(unwrap_any(DeserrError::<C>::error(
None,
deserr::ErrorKind::IncorrectValueKind {
actual: value,
accepted: &[ValueKind::String],
},
location,
))),
}
}
}
impl<C: Default + ErrorCode> MergeWithError<IndexUidFormatError> for DeserrError<C> {
fn merge(
_self_: Option<Self>,
@ -56,6 +31,10 @@ impl<C: Default + ErrorCode> MergeWithError<IndexUidFormatError> for DeserrError
}
}
fn parse_uuid_from_str(s: &str) -> Result<Uuid, TakeErrorMessage<uuid::Error>> {
Uuid::parse_str(s).map_err(TakeErrorMessage)
}
#[derive(Debug, DeserializeFromValue)]
#[deserr(error = DeserrError, rename_all = camelCase, deny_unknown_fields)]
pub struct CreateApiKey {
@ -63,12 +42,9 @@ pub struct CreateApiKey {
pub description: Option<String>,
#[deserr(error = DeserrError<InvalidApiKeyName>)]
pub name: Option<String>,
#[deserr(default = Uuid::new_v4(), error = DeserrError<InvalidApiKeyUid>)]
#[deserr(default = Uuid::new_v4(), error = DeserrError<InvalidApiKeyUid>, from(&String) = parse_uuid_from_str -> TakeErrorMessage<uuid::Error>)]
pub uid: KeyId,
// Value at `.name` is invalid. It is a dictionary, but is expected to be an array of strings containing action names.
// Value `indeex.create` at `.name[1]` is invalid. It is expected to be one of: ....
#[deserr(error = DeserrError<InvalidApiKeyActions>)]
//, expected = "an array of string containing action names.")]
pub actions: Vec<Action>,
#[deserr(error = DeserrError<InvalidApiKeyIndexes>)]
pub indexes: Vec<StarOr<IndexUid>>,