draft without error handling

This commit is contained in:
刘瀚骋 2021-09-15 18:57:18 +08:00
parent 8f6b6c9042
commit 8748df2ca4
3 changed files with 265 additions and 1 deletions

View file

@ -62,6 +62,9 @@ pub enum UserError {
InvalidFilter(pest::error::Error<ParserRule>),
InvalidFilterAttribute(pest::error::Error<ParserRule>),
InvalidGeoField { document_id: Value, object: Value },
InvalidFilterAttributeNom,
InvalidFilterValue,
InvalidSortName { name: String },
InvalidSortableAttribute { field: String, valid_fields: HashSet<String> },
SortRankingRuleMissing,
InvalidStoreFile,
@ -82,6 +85,11 @@ impl From<io::Error> for Error {
Error::IoError(error)
}
}
impl From<std::num::ParseFloatError> for UserError {
fn from(_: std::num::ParseFloatError) -> UserError {
UserError::InvalidFilterValue
}
}
impl From<fst::Error> for Error {
fn from(error: fst::Error) -> Error {
@ -208,6 +216,9 @@ impl StdError for InternalError {}
impl fmt::Display for UserError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
//TODO
Self::InvalidFilterAttributeNom => f.write_str("parser error "),
Self::InvalidFilterValue => f.write_str("parser error "),
Self::AttributeLimitReached => f.write_str("maximum number of attributes reached"),
Self::CriterionError(error) => write!(f, "{}", error),
Self::DocumentLimitReached => f.write_str("maximum number of documents reached"),