ng_oxigraph/oxigraph/storage/
error.rs1use crate::oxigraph::io::{RdfFormat, RdfParseError};
2use crate::oxigraph::storage::numeric_encoder::EncodedTerm;
3use crate::oxrdf::TermRef;
4use oxiri::IriParseError;
5use std::error::Error;
6use std::io;
7
8#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum StorageError {
12 #[error(transparent)]
14 Io(#[from] io::Error),
15 #[error(transparent)]
17 Corruption(#[from] CorruptionError),
18 #[doc(hidden)]
19 #[error("{0}")]
20 Other(#[source] Box<dyn Error + Send + Sync + 'static>),
21}
22
23impl From<StorageError> for io::Error {
24 #[inline]
25 fn from(error: StorageError) -> Self {
26 match error {
27 StorageError::Io(error) => error,
28 StorageError::Corruption(error) => error.into(),
29 StorageError::Other(error) => Self::new(io::ErrorKind::Other, error),
30 }
31 }
32}
33
34#[derive(Debug, thiserror::Error)]
36#[error(transparent)]
37pub struct CorruptionError(#[from] CorruptionErrorKind);
38
39#[derive(Debug, thiserror::Error)]
41enum CorruptionErrorKind {
42 #[error("{0}")]
43 Msg(String),
44 #[error("{0}")]
45 Other(#[source] Box<dyn Error + Send + Sync + 'static>),
46}
47
48impl CorruptionError {
49 #[inline]
51 pub(crate) fn new(error: impl Into<Box<dyn Error + Send + Sync + 'static>>) -> Self {
52 Self(CorruptionErrorKind::Other(error.into()))
53 }
54
55 #[inline]
56 pub(crate) fn from_encoded_term(encoded: &EncodedTerm, term: &TermRef<'_>) -> Self {
57 Self::msg(format!("Invalid term encoding {encoded:?} for {term}"))
59 }
60
61 #[inline]
62 pub(crate) fn from_missing_column_family_name(name: &'static str) -> Self {
63 Self::msg(format!("Column family {name} does not exist"))
65 }
66
67 #[inline]
69 pub(crate) fn msg(msg: impl Into<String>) -> Self {
70 Self(CorruptionErrorKind::Msg(msg.into()))
71 }
72}
73
74impl From<CorruptionError> for io::Error {
75 #[inline]
76 fn from(error: CorruptionError) -> Self {
77 Self::new(io::ErrorKind::InvalidData, error)
78 }
79}
80
81#[derive(Debug, thiserror::Error)]
83pub enum LoaderError {
84 #[error(transparent)]
86 Parsing(#[from] RdfParseError),
87 #[error(transparent)]
89 Storage(#[from] StorageError),
90 #[error("Invalid base IRI '{iri}': {error}")]
92 InvalidBaseIri {
93 iri: String,
95 #[source]
97 error: IriParseError,
98 },
99}
100
101impl From<LoaderError> for io::Error {
102 #[inline]
103 fn from(error: LoaderError) -> Self {
104 match error {
105 LoaderError::Storage(error) => error.into(),
106 LoaderError::Parsing(error) => error.into(),
107 LoaderError::InvalidBaseIri { .. } => {
108 Self::new(io::ErrorKind::InvalidInput, error.to_string())
109 }
110 }
111 }
112}
113
114#[derive(Debug, thiserror::Error)]
116pub enum SerializerError {
117 #[error(transparent)]
119 Io(#[from] io::Error),
120 #[error(transparent)]
122 Storage(#[from] StorageError),
123 #[error("A RDF format supporting datasets was expected, {0} found")]
125 DatasetFormatExpected(RdfFormat),
126}
127
128impl From<SerializerError> for io::Error {
129 #[inline]
130 fn from(error: SerializerError) -> Self {
131 match error {
132 SerializerError::Storage(error) => error.into(),
133 SerializerError::Io(error) => error,
134 SerializerError::DatasetFormatExpected(_) => {
135 Self::new(io::ErrorKind::InvalidInput, error.to_string())
136 }
137 }
138 }
139}