use tantivy::schema::DocParsingError as TantivyDocParsingError;
use thiserror::Error;
#[derive(Error, Debug)]
#[error("{0}")]
pub struct QueryParserError(#[from] anyhow::Error);
impl From<tantivy::query::QueryParserError> for QueryParserError {
fn from(tantivy_error: tantivy::query::QueryParserError) -> Self {
QueryParserError(From::from(tantivy_error))
}
}
#[derive(Debug, Error, PartialEq)]
pub enum DocParsingError {
#[error("The provided string is not a valid JSON object. {0}")]
NotJsonObject(String),
#[error("The field '{0}' could not be parsed: {1}")]
ValueError(String, String),
#[error("The document contains a field that is not declared in the schema: {0:?}")]
NoSuchFieldInSchema(String),
#[error("The document contains an array of values but a single value is expected: {0:?}")]
MultiValuesNotSupported(String),
#[error("The document must contain field {0:?}. As a fast field, it is implicitly required.")]
RequiredFastField(String),
}
impl From<TantivyDocParsingError> for DocParsingError {
fn from(value: TantivyDocParsingError) -> Self {
match value {
TantivyDocParsingError::InvalidJson(text) => DocParsingError::NoSuchFieldInSchema(text),
TantivyDocParsingError::ValueError(text, error) => {
DocParsingError::ValueError(text, format!("{:?}", error))
}
}
}
}