use crate::io::RdfParseError;
use crate::model::NamedNode;
use crate::sparql::results::QueryResultsParseError as ResultsParseError;
use crate::sparql::SparqlSyntaxError;
use crate::storage::StorageError;
use std::convert::Infallible;
use std::error::Error;
use std::io;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum EvaluationError {
#[error(transparent)]
Parsing(#[from] SparqlSyntaxError),
#[error(transparent)]
Storage(#[from] StorageError),
#[error(transparent)]
GraphParsing(#[from] RdfParseError),
#[error(transparent)]
ResultsParsing(#[from] ResultsParseError),
#[error(transparent)]
ResultsSerialization(#[from] io::Error),
#[error("{0}")]
Service(#[source] Box<dyn Error + Send + Sync + 'static>),
#[error("The graph {0} already exists")]
GraphAlreadyExists(NamedNode),
#[error("The graph {0} does not exist")]
GraphDoesNotExist(NamedNode),
#[error("The variable encoding the service name is unbound")]
UnboundService,
#[error("The service {0} is not supported")]
UnsupportedService(NamedNode),
#[error("The content media type {0} is not supported")]
UnsupportedContentType(String),
#[error("The service is not returning solutions but a boolean or a graph")]
ServiceDoesNotReturnSolutions,
#[error("The query results are not a RDF graph")]
NotAGraph,
}
impl From<Infallible> for EvaluationError {
#[inline]
fn from(error: Infallible) -> Self {
match error {}
}
}
impl From<EvaluationError> for io::Error {
#[inline]
fn from(error: EvaluationError) -> Self {
match error {
EvaluationError::Parsing(error) => Self::new(io::ErrorKind::InvalidData, error),
EvaluationError::GraphParsing(error) => error.into(),
EvaluationError::ResultsParsing(error) => error.into(),
EvaluationError::ResultsSerialization(error) => error,
EvaluationError::Storage(error) => error.into(),
EvaluationError::Service(error) => match error.downcast() {
Ok(error) => *error,
Err(error) => Self::other(error),
},
EvaluationError::GraphAlreadyExists(_)
| EvaluationError::GraphDoesNotExist(_)
| EvaluationError::UnboundService
| EvaluationError::UnsupportedService(_)
| EvaluationError::UnsupportedContentType(_)
| EvaluationError::ServiceDoesNotReturnSolutions
| EvaluationError::NotAGraph => Self::new(io::ErrorKind::InvalidInput, error),
}
}
}