1use crate::expression::ExpressionEvaluationError;
2use oxrdf::{NamedNode, Term, Variable};
3use spargebra::SparqlSyntaxError;
4use std::convert::Infallible;
5use std::error::Error;
6use std::ops::RangeInclusive;
7
8#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum QueryEvaluationError {
12 #[error(transparent)]
14 Dataset(Box<dyn Error + Send + Sync>),
15 #[error("{0}")]
17 Service(#[source] Box<dyn Error + Send + Sync>),
18 #[error("The SPARQL query does not contains variable {0} in its SELECT projection")]
20 NotExistingSubstitutedVariable(Variable),
21 #[error("The SPARQL dataset returned the default graph even if a named graph is expected")]
23 UnexpectedDefaultGraph,
24 #[error("The custom function {0} is not supported")]
26 UnsupportedCustomFunction(NamedNode),
27 #[error("The custom function {name} requires between {} and {} arguments, but {actual} were given", .expected.start(), .expected.end())]
29 UnsupportedCustomFunctionArity {
30 name: NamedNode,
31 expected: RangeInclusive<usize>,
32 actual: usize,
33 },
34 #[error("The variable encoding the service name is unbound")]
36 UnboundService,
37 #[error("{0} is not a valid service name")]
39 InvalidServiceName(Term),
40 #[error("The service {0} is not supported")]
42 UnsupportedService(NamedNode),
43 #[cfg(feature = "sparql-12")]
44 #[error("The SPARQL dataset returned a triple term that is not a valid RDF 1.2 term")]
45 InvalidStorageTripleTerm,
46 #[error("The SPARQL operation has been cancelled")]
47 Cancelled,
48 #[doc(hidden)]
49 #[error(transparent)]
50 Unexpected(Box<dyn Error + Send + Sync>),
51}
52
53impl From<Infallible> for QueryEvaluationError {
54 #[inline]
55 fn from(error: Infallible) -> Self {
56 match error {}
57 }
58}
59
60#[doc(hidden)]
62impl From<SparqlSyntaxError> for QueryEvaluationError {
63 #[inline]
64 fn from(error: SparqlSyntaxError) -> Self {
65 Self::Unexpected(Box::new(error))
66 }
67}
68
69impl From<ExpressionEvaluationError<Self>> for QueryEvaluationError {
70 #[inline]
71 fn from(error: ExpressionEvaluationError<Self>) -> Self {
72 match error {
73 ExpressionEvaluationError::Context(e) => e,
74 ExpressionEvaluationError::UnsupportedCustomFunction(name) => {
75 Self::UnsupportedCustomFunction(name)
76 }
77 ExpressionEvaluationError::UnsupportedCustomFunctionArity {
78 name,
79 expected,
80 actual,
81 } => Self::UnsupportedCustomFunctionArity {
82 name,
83 expected,
84 actual,
85 },
86 }
87 }
88}