mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-02-02 16:43:34 +01:00
clean the errors
This commit is contained in:
parent
72a9071203
commit
3e5550c910
@ -1,6 +1,7 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use nom::{Parser, error::{self, ParseError}};
|
use nom::error::{self, ParseError};
|
||||||
|
use nom::Parser;
|
||||||
|
|
||||||
use crate::{IResult, Span};
|
use crate::{IResult, Span};
|
||||||
|
|
||||||
@ -31,11 +32,14 @@ impl<E> ExtendNomError<E> for nom::Err<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// cut a parser and map the error
|
/// cut a parser and map the error
|
||||||
pub fn cut_with_err<'a, O>(mut parser: impl FnMut(Span<'a>) -> IResult<O>, mut with: impl FnMut(Error<'a>) -> Error<'a>) -> impl FnMut(Span<'a>) -> IResult<O> {
|
pub fn cut_with_err<'a, O>(
|
||||||
move |input| match parser.parse(input) {
|
mut parser: impl FnMut(Span<'a>) -> IResult<O>,
|
||||||
Err(nom::Err::Error(e)) => Err(nom::Err::Failure(with(e))),
|
mut with: impl FnMut(Error<'a>) -> Error<'a>,
|
||||||
rest => rest,
|
) -> impl FnMut(Span<'a>) -> IResult<O> {
|
||||||
}
|
move |input| match parser.parse(input) {
|
||||||
|
Err(nom::Err::Error(e)) => Err(nom::Err::Failure(with(e))),
|
||||||
|
rest => rest,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -50,14 +54,12 @@ pub enum ErrorKind<'a> {
|
|||||||
Geo,
|
Geo,
|
||||||
MisusedGeo,
|
MisusedGeo,
|
||||||
InvalidPrimary,
|
InvalidPrimary,
|
||||||
ReservedKeyword,
|
|
||||||
ExpectedEof,
|
ExpectedEof,
|
||||||
ExpectedValue,
|
ExpectedValue,
|
||||||
MissingClosingDelimiter(char),
|
MissingClosingDelimiter(char),
|
||||||
UnexpectedInput(Vec<&'a str>),
|
|
||||||
Context(&'a str),
|
|
||||||
Char(char),
|
Char(char),
|
||||||
Unreachable,
|
InternalError(error::ErrorKind),
|
||||||
|
External(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Error<'a> {
|
impl<'a> Error<'a> {
|
||||||
@ -68,66 +70,15 @@ impl<'a> Error<'a> {
|
|||||||
match self.kind {
|
match self.kind {
|
||||||
ErrorKind::Char(c) => c,
|
ErrorKind::Char(c) => c,
|
||||||
_ => panic!("Internal filter parser error"),
|
_ => panic!("Internal filter parser error"),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ParseError<Span<'a>> for Error<'a> {
|
impl<'a> ParseError<Span<'a>> for Error<'a> {
|
||||||
fn from_error_kind(input: Span<'a>, kind: error::ErrorKind) -> Self {
|
fn from_error_kind(input: Span<'a>, kind: error::ErrorKind) -> Self {
|
||||||
let kind = match kind {
|
let kind = match kind {
|
||||||
error::ErrorKind::Eof => ErrorKind::ExpectedEof,
|
error::ErrorKind::Eof => ErrorKind::ExpectedEof,
|
||||||
error::ErrorKind::Tag => ErrorKind::UnexpectedInput(Vec::new()),
|
kind => ErrorKind::InternalError(kind),
|
||||||
error::ErrorKind::MapRes => todo!(),
|
|
||||||
error::ErrorKind::MapOpt => todo!(),
|
|
||||||
error::ErrorKind::Alt => todo!(),
|
|
||||||
error::ErrorKind::IsNot => todo!(),
|
|
||||||
error::ErrorKind::IsA => todo!(),
|
|
||||||
error::ErrorKind::SeparatedList => todo!(),
|
|
||||||
error::ErrorKind::SeparatedNonEmptyList => todo!(),
|
|
||||||
error::ErrorKind::Many0 => todo!(),
|
|
||||||
error::ErrorKind::Many1 => todo!(),
|
|
||||||
error::ErrorKind::ManyTill => todo!(),
|
|
||||||
error::ErrorKind::Count => todo!(),
|
|
||||||
error::ErrorKind::TakeUntil => todo!(),
|
|
||||||
error::ErrorKind::LengthValue => todo!(),
|
|
||||||
error::ErrorKind::TagClosure => todo!(),
|
|
||||||
error::ErrorKind::Alpha => todo!(),
|
|
||||||
error::ErrorKind::Digit => todo!(),
|
|
||||||
error::ErrorKind::HexDigit => todo!(),
|
|
||||||
error::ErrorKind::OctDigit => todo!(),
|
|
||||||
error::ErrorKind::AlphaNumeric => todo!(),
|
|
||||||
error::ErrorKind::Space => todo!(),
|
|
||||||
error::ErrorKind::MultiSpace => todo!(),
|
|
||||||
error::ErrorKind::LengthValueFn => todo!(),
|
|
||||||
error::ErrorKind::Switch => todo!(),
|
|
||||||
error::ErrorKind::TagBits => todo!(),
|
|
||||||
error::ErrorKind::OneOf => todo!(),
|
|
||||||
error::ErrorKind::NoneOf => todo!(),
|
|
||||||
error::ErrorKind::Char => todo!(),
|
|
||||||
error::ErrorKind::CrLf => todo!(),
|
|
||||||
error::ErrorKind::RegexpMatch => todo!(),
|
|
||||||
error::ErrorKind::RegexpMatches => todo!(),
|
|
||||||
error::ErrorKind::RegexpFind => todo!(),
|
|
||||||
error::ErrorKind::RegexpCapture => todo!(),
|
|
||||||
error::ErrorKind::RegexpCaptures => todo!(),
|
|
||||||
error::ErrorKind::TakeWhile1 => ErrorKind::Unreachable,
|
|
||||||
error::ErrorKind::Complete => todo!(),
|
|
||||||
error::ErrorKind::Fix => todo!(),
|
|
||||||
error::ErrorKind::Escaped => todo!(),
|
|
||||||
error::ErrorKind::EscapedTransform => todo!(),
|
|
||||||
error::ErrorKind::NonEmpty => todo!(),
|
|
||||||
error::ErrorKind::ManyMN => todo!(),
|
|
||||||
error::ErrorKind::Not => todo!(),
|
|
||||||
error::ErrorKind::Permutation => todo!(),
|
|
||||||
error::ErrorKind::Verify => todo!(),
|
|
||||||
error::ErrorKind::TakeTill1 => todo!(),
|
|
||||||
error::ErrorKind::TakeWhileMN => todo!(),
|
|
||||||
error::ErrorKind::TooLarge => todo!(),
|
|
||||||
error::ErrorKind::Many0Count => todo!(),
|
|
||||||
error::ErrorKind::Many1Count => todo!(),
|
|
||||||
error::ErrorKind::Float => todo!(),
|
|
||||||
error::ErrorKind::Satisfy => todo!(),
|
|
||||||
error::ErrorKind::Fail => todo!(),
|
|
||||||
};
|
};
|
||||||
Self { context: input, kind }
|
Self { context: input, kind }
|
||||||
}
|
}
|
||||||
@ -176,13 +127,11 @@ impl<'a> Display for Error<'a> {
|
|||||||
ErrorKind::Char(c) => {
|
ErrorKind::Char(c) => {
|
||||||
panic!("Tried to display a char error with `{}`", c)
|
panic!("Tried to display a char error with `{}`", c)
|
||||||
}
|
}
|
||||||
ErrorKind::ReservedKeyword => writeln!(f, "reserved keyword")?,
|
ErrorKind::InternalError(kind) => writeln!(
|
||||||
ErrorKind::UnexpectedInput(ref v) => writeln!(f, "Unexpected input found `{}`, vec: `{:?}`", input, v)?,
|
|
||||||
ErrorKind::Context(_) => todo!(),
|
|
||||||
ErrorKind::Unreachable => writeln!(
|
|
||||||
f,
|
f,
|
||||||
"Encountered an internal error while parsing your filter. Please fill an issue"
|
"Encountered an internal `{:?}` error while parsing your filter. Please fill an issue", kind
|
||||||
)?,
|
)?,
|
||||||
|
ErrorKind::External(ref error) => writeln!(f, "{}", error)?,
|
||||||
}
|
}
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user