Convert error to thiserror

This converts just one `SerializerError` to use `thiserror` crate, removing some code.
pull/778/head
Yuri Astrakhan 11 months ago committed by Thomas Tanon
parent f5de5d3e98
commit 1c3f054836
  1. 21
      Cargo.lock
  2. 1
      Cargo.toml
  3. 1
      lib/oxigraph/Cargo.toml
  4. 49
      lib/oxigraph/src/storage/error.rs

21
Cargo.lock generated

@ -1068,6 +1068,7 @@ dependencies = [
"sparesults", "sparesults",
"spargebra", "spargebra",
"sparopt", "sparopt",
"thiserror",
"zstd", "zstd",
] ]
@ -1847,6 +1848,26 @@ dependencies = [
"term", "term",
] ]
[[package]]
name = "thiserror"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.34" version = "0.3.34"

@ -60,6 +60,7 @@ sha1 = "0.10"
sha2 = "0.10" sha2 = "0.10"
siphasher = ">=0.3, <2.0" siphasher = ">=0.3, <2.0"
text-diff = "0.4" text-diff = "0.4"
thiserror = "1"
time = "0.3" time = "0.3"
tokio = "1.29" tokio = "1.29"
url = "2.4" url = "2.4"

@ -43,6 +43,7 @@ siphasher.workspace = true
sparesults = { workspace = true, features = ["rdf-star"] } sparesults = { workspace = true, features = ["rdf-star"] }
spargebra = { workspace = true, features = ["rdf-star", "sep-0002", "sep-0006"] } spargebra = { workspace = true, features = ["rdf-star", "sep-0002", "sep-0006"] }
sparopt = { workspace = true, features = ["rdf-star", "sep-0002", "sep-0006"] } sparopt = { workspace = true, features = ["rdf-star", "sep-0002", "sep-0006"] }
thiserror.workspace = true
[target.'cfg(not(target_family = "wasm"))'.dependencies] [target.'cfg(not(target_family = "wasm"))'.dependencies]
libc.workspace = true libc.workspace = true

@ -2,6 +2,7 @@ use crate::io::{ParseError, RdfFormat};
use oxiri::IriParseError; use oxiri::IriParseError;
use std::error::Error; use std::error::Error;
use std::{fmt, io}; use std::{fmt, io};
use thiserror::Error;
/// An error related to storage operations (reads, writes...). /// An error related to storage operations (reads, writes...).
#[derive(Debug)] #[derive(Debug)]
@ -185,55 +186,19 @@ impl From<LoaderError> for io::Error {
} }
/// An error raised while writing a file from a [`Store`](crate::store::Store). /// An error raised while writing a file from a [`Store`](crate::store::Store).
#[derive(Debug)] #[derive(Debug, Error)]
pub enum SerializerError { pub enum SerializerError {
/// An error raised while writing the content. /// An error raised while writing the content.
Io(io::Error), #[error(transparent)]
Io(#[from] io::Error),
/// An error raised during the lookup in the store. /// An error raised during the lookup in the store.
Storage(StorageError), #[error(transparent)]
Storage(#[from] StorageError),
/// A format compatible with [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) is required. /// A format compatible with [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset) is required.
#[error("A RDF format supporting datasets was expected, {0} found")]
DatasetFormatExpected(RdfFormat), DatasetFormatExpected(RdfFormat),
} }
impl fmt::Display for SerializerError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
Self::Storage(e) => e.fmt(f),
Self::DatasetFormatExpected(format) => write!(
f,
"A RDF format supporting datasets was expected, {format} found"
),
}
}
}
impl Error for SerializerError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Storage(e) => Some(e),
Self::DatasetFormatExpected(_) => None,
}
}
}
impl From<io::Error> for SerializerError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<StorageError> for SerializerError {
#[inline]
fn from(error: StorageError) -> Self {
Self::Storage(error)
}
}
impl From<SerializerError> for io::Error { impl From<SerializerError> for io::Error {
#[inline] #[inline]
fn from(error: SerializerError) -> Self { fn from(error: SerializerError) -> Self {

Loading…
Cancel
Save