rdf_fusion/
error.rs

1use oxrdfio::{RdfFormat, RdfParseError};
2use rdf_fusion_execution::sparql::error::QueryEvaluationError;
3use rdf_fusion_model::IriParseError;
4use rdf_fusion_model::StorageError;
5use std::io;
6
7/// An error raised while loading a file into a [`Store`](crate::store::Store).
8#[derive(Debug, thiserror::Error)]
9pub enum LoaderError {
10    /// An error raised while reading the file.
11    #[error(transparent)]
12    Parsing(#[from] RdfParseError),
13    /// An error raised during the insertion in the store.
14    #[error(transparent)]
15    Storage(#[from] StorageError),
16    /// The base IRI is invalid.
17    #[error("Invalid base IRI '{iri}': {error}")]
18    InvalidBaseIri {
19        /// The IRI itself.
20        iri: String,
21        /// The parsing error.
22        #[source]
23        error: IriParseError,
24    },
25}
26
27impl From<LoaderError> for io::Error {
28    #[inline]
29    fn from(error: LoaderError) -> Self {
30        match error {
31            LoaderError::Storage(error) => error.into(),
32            LoaderError::Parsing(error) => error.into(),
33            LoaderError::InvalidBaseIri { .. } => {
34                Self::new(io::ErrorKind::InvalidInput, error.to_string())
35            }
36        }
37    }
38}
39
40/// An error raised while writing a file from a [`Store`](crate::store::Store).
41
42#[derive(Debug, thiserror::Error)]
43
44pub enum SerializerError {
45    /// An error raised while writing the content.
46    #[error(transparent)]
47    Io(#[from] io::Error),
48
49    /// An error raised during accessing the quads in the [`Store`](crate::store::Store).
50    #[error(transparent)]
51    Evaluation(#[from] QueryEvaluationError),
52
53    /// A format compatible with [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) is required.
54    #[error("A RDF format supporting datasets was expected, {0} found")]
55    DatasetFormatExpected(RdfFormat),
56}