1use crate::io::RdfParseError;
2use crate::model::NamedNode;
3use crate::store::{CorruptionError, StorageError};
4use oxrdf::{Term, Variable};
5use spareval::QueryEvaluationError;
6use spargebra::SparqlSyntaxError;
7use std::convert::Infallible;
8use std::error::Error;
9use std::io;
10
11#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum UpdateEvaluationError {
15 #[error(transparent)]
17 Storage(#[from] StorageError),
18 #[error(transparent)]
20 GraphParsing(#[from] RdfParseError),
21 #[error("{0}")]
23 Service(#[source] Box<dyn Error + Send + Sync + 'static>),
24 #[error("The graph {0} already exists")]
26 GraphAlreadyExists(NamedNode),
27 #[error("The graph {0} does not exist")]
29 GraphDoesNotExist(NamedNode),
30 #[error("The variable encoding the service name is unbound")]
32 UnboundService,
33 #[error("{0} is not a valid service name")]
35 InvalidServiceName(Term),
36 #[error("The service {0} is not supported")]
38 UnsupportedService(NamedNode),
39 #[error("The content media type {0} is not supported")]
41 UnsupportedContentType(String),
42 #[error("The SPARQL query does not contains variable {0} in its SELECT projection")]
44 NotExistingSubstitutedVariable(Variable),
45 #[doc(hidden)]
46 #[error(transparent)]
47 Unexpected(Box<dyn Error + Send + Sync>),
48}
49
50impl From<Infallible> for UpdateEvaluationError {
51 #[inline]
52 fn from(error: Infallible) -> Self {
53 match error {}
54 }
55}
56
57impl From<QueryEvaluationError> for UpdateEvaluationError {
58 fn from(error: QueryEvaluationError) -> Self {
59 match error {
60 QueryEvaluationError::Dataset(error) => match error.downcast() {
61 Ok(error) => Self::Storage(*error),
62 Err(error) => Self::Unexpected(error),
63 },
64 QueryEvaluationError::Service(error) => Self::Service(error),
65 QueryEvaluationError::UnexpectedDefaultGraph => Self::Storage(
66 CorruptionError::new("Unexpected default graph returned from the storage").into(),
67 ),
68 QueryEvaluationError::UnboundService => Self::UnboundService,
69 QueryEvaluationError::UnsupportedService(name) => Self::UnsupportedService(name),
70 QueryEvaluationError::NotExistingSubstitutedVariable(v) => {
71 Self::NotExistingSubstitutedVariable(v)
72 }
73 QueryEvaluationError::InvalidServiceName(name) => Self::InvalidServiceName(name),
74 #[cfg(feature = "rdf-12")]
75 QueryEvaluationError::InvalidStorageTripleTerm => Self::Storage(
76 CorruptionError::new(
77 "The storage returned a triple term that is not a valid RDF 1.2 term",
78 )
79 .into(),
80 ),
81 e => Self::Unexpected(Box::new(e)),
82 }
83 }
84}
85
86impl From<UpdateEvaluationError> for io::Error {
87 #[inline]
88 fn from(error: UpdateEvaluationError) -> Self {
89 match error {
90 UpdateEvaluationError::Storage(error) => error.into(),
91 UpdateEvaluationError::GraphParsing(error) => error.into(),
92 UpdateEvaluationError::Service(error) | UpdateEvaluationError::Unexpected(error) => {
93 match error.downcast() {
94 Ok(error) => *error,
95 Err(error) => Self::other(error),
96 }
97 }
98 UpdateEvaluationError::GraphAlreadyExists(_)
99 | UpdateEvaluationError::GraphDoesNotExist(_)
100 | UpdateEvaluationError::UnboundService
101 | UpdateEvaluationError::InvalidServiceName(_)
102 | UpdateEvaluationError::UnsupportedService(_)
103 | UpdateEvaluationError::UnsupportedContentType(_)
104 | UpdateEvaluationError::NotExistingSubstitutedVariable(_) => {
105 Self::new(io::ErrorKind::InvalidInput, error)
106 }
107 }
108 }
109}
110
111#[doc(hidden)]
113impl From<SparqlSyntaxError> for UpdateEvaluationError {
114 #[inline]
115 fn from(error: SparqlSyntaxError) -> Self {
116 Self::Unexpected(Box::new(error))
117 }
118}