oxigraph/storage/
error.rs1use crate::io::{RdfFormat, RdfParseError};
2use oxiri::IriParseError;
3use std::error::Error;
4use std::io;
5
6#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum StorageError {
10 #[error(transparent)]
12 Io(#[from] io::Error),
13 #[error(transparent)]
15 Corruption(#[from] CorruptionError),
16 #[doc(hidden)]
17 #[error("{0}")]
18 Other(#[source] Box<dyn Error + Send + Sync + 'static>),
19}
20
21impl From<StorageError> for io::Error {
22 #[inline]
23 fn from(error: StorageError) -> Self {
24 match error {
25 StorageError::Io(error) => error,
26 StorageError::Corruption(error) => error.into(),
27 StorageError::Other(error) => Self::other(error),
28 }
29 }
30}
31
32#[derive(Debug, thiserror::Error)]
34#[error(transparent)]
35pub struct CorruptionError(#[from] CorruptionErrorKind);
36
37#[derive(Debug, thiserror::Error)]
39enum CorruptionErrorKind {
40 #[error("{0}")]
41 Msg(String),
42 #[error("{0}")]
43 Other(#[source] Box<dyn Error + Send + Sync + 'static>),
44}
45
46impl CorruptionError {
47 #[inline]
49 pub(crate) fn new(error: impl Into<Box<dyn Error + Send + Sync + 'static>>) -> Self {
50 Self(CorruptionErrorKind::Other(error.into()))
51 }
52
53 #[inline]
54 #[cfg(all(not(target_family = "wasm"), feature = "rocksdb"))]
55 pub(crate) fn from_missing_column_family_name(name: &'static str) -> Self {
56 Self::msg(format!("Column family {name} does not exist"))
58 }
59
60 #[inline]
62 pub(crate) fn msg(msg: impl Into<String>) -> Self {
63 Self(CorruptionErrorKind::Msg(msg.into()))
64 }
65}
66
67impl From<CorruptionError> for io::Error {
68 #[inline]
69 fn from(error: CorruptionError) -> Self {
70 Self::new(io::ErrorKind::InvalidData, error)
71 }
72}
73
74#[derive(Debug, thiserror::Error)]
76pub enum LoaderError {
77 #[error(transparent)]
79 Parsing(#[from] RdfParseError),
80 #[error(transparent)]
82 Storage(#[from] StorageError),
83 #[error("Invalid base IRI '{iri}': {error}")]
85 InvalidBaseIri {
86 iri: String,
88 #[source]
90 error: IriParseError,
91 },
92}
93
94impl From<LoaderError> for io::Error {
95 #[inline]
96 fn from(error: LoaderError) -> Self {
97 match error {
98 LoaderError::Storage(error) => error.into(),
99 LoaderError::Parsing(error) => error.into(),
100 LoaderError::InvalidBaseIri { .. } => {
101 Self::new(io::ErrorKind::InvalidInput, error.to_string())
102 }
103 }
104 }
105}
106
107#[derive(Debug, thiserror::Error)]
109pub enum SerializerError {
110 #[error(transparent)]
112 Io(#[from] io::Error),
113 #[error(transparent)]
115 Storage(#[from] StorageError),
116 #[error("A RDF format supporting datasets was expected, {0} found")]
118 DatasetFormatExpected(RdfFormat),
119}
120
121impl From<SerializerError> for io::Error {
122 #[inline]
123 fn from(error: SerializerError) -> Self {
124 match error {
125 SerializerError::Storage(error) => error.into(),
126 SerializerError::Io(error) => error,
127 SerializerError::DatasetFormatExpected(_) => {
128 Self::new(io::ErrorKind::InvalidInput, error.to_string())
129 }
130 }
131 }
132}