Many other errors

pull/745/head
Yuri Astrakhan 11 months ago
parent 1a064ede53
commit 65eed84256
  1. 4
      Cargo.lock
  2. 111
      lib/oxigraph/src/sparql/error.rs
  3. 91
      lib/oxigraph/src/storage/error.rs
  4. 31
      lib/oxigraph/src/storage/small_string.rs
  5. 1
      lib/oxrdfio/Cargo.toml
  6. 43
      lib/oxrdfio/src/error.rs
  7. 1
      lib/oxrdfxml/Cargo.toml
  8. 43
      lib/oxrdfxml/src/error.rs
  9. 1
      lib/oxttl/Cargo.toml
  10. 43
      lib/oxttl/src/toolkit/error.rs
  11. 1
      lib/sparesults/Cargo.toml
  12. 43
      lib/sparesults/src/error.rs

4
Cargo.lock generated

@ -1145,6 +1145,7 @@ dependencies = [
"oxrdf", "oxrdf",
"oxrdfxml", "oxrdfxml",
"oxttl", "oxttl",
"thiserror",
"tokio", "tokio",
] ]
@ -1156,6 +1157,7 @@ dependencies = [
"oxiri", "oxiri",
"oxrdf", "oxrdf",
"quick-xml", "quick-xml",
"thiserror",
"tokio", "tokio",
] ]
@ -1184,6 +1186,7 @@ dependencies = [
"oxilangtag", "oxilangtag",
"oxiri", "oxiri",
"oxrdf", "oxrdf",
"thiserror",
"tokio", "tokio",
] ]
@ -1745,6 +1748,7 @@ dependencies = [
"memchr", "memchr",
"oxrdf", "oxrdf",
"quick-xml", "quick-xml",
"thiserror",
"tokio", "tokio",
] ]

@ -5,93 +5,54 @@ use crate::sparql::ParseError;
use crate::storage::StorageError; use crate::storage::StorageError;
use std::convert::Infallible; use std::convert::Infallible;
use std::error::Error; use std::error::Error;
use std::{fmt, io}; use std::io;
use thiserror::Error;
/// A SPARQL evaluation error. /// A SPARQL evaluation error.
#[derive(Debug)] #[derive(Debug, Error)]
#[non_exhaustive] #[non_exhaustive]
pub enum EvaluationError { pub enum EvaluationError {
/// An error in SPARQL parsing. /// An error in SPARQL parsing.
Parsing(ParseError), #[error(transparent)]
Parsing(#[from] ParseError),
/// An error from the storage. /// An error from the storage.
Storage(StorageError), #[error(transparent)]
Storage(#[from] StorageError),
/// An error while parsing an external RDF file. /// An error while parsing an external RDF file.
GraphParsing(RdfParseError), #[error(transparent)]
GraphParsing(#[from] RdfParseError),
/// An error while parsing an external result file (likely from a federated query). /// An error while parsing an external result file (likely from a federated query).
ResultsParsing(ResultsParseError), #[error(transparent)]
ResultsParsing(#[from] ResultsParseError),
/// An error returned during results serialization. /// An error returned during results serialization.
ResultsSerialization(io::Error), #[error(transparent)]
ResultsSerialization(#[from] io::Error),
/// Error during `SERVICE` evaluation /// Error during `SERVICE` evaluation
Service(Box<dyn Error + Send + Sync + 'static>), #[error("{0}")]
Service(#[source] Box<dyn Error + Send + Sync + 'static>),
/// Error when `CREATE` tries to create an already existing graph /// Error when `CREATE` tries to create an already existing graph
#[error("The graph {0} already exists")]
GraphAlreadyExists(NamedNode), GraphAlreadyExists(NamedNode),
/// Error when `DROP` or `CLEAR` tries to remove a not existing graph /// Error when `DROP` or `CLEAR` tries to remove a not existing graph
#[error("The graph {0} does not exist")]
GraphDoesNotExist(NamedNode), GraphDoesNotExist(NamedNode),
/// The variable storing the `SERVICE` name is unbound /// The variable storing the `SERVICE` name is unbound
#[error("The variable encoding the service name is unbound")]
UnboundService, UnboundService,
/// The given `SERVICE` is not supported /// The given `SERVICE` is not supported
#[error("The service {0} is not supported")]
UnsupportedService(NamedNode), UnsupportedService(NamedNode),
/// The given content media type returned from an HTTP response is not supported (`SERVICE` and `LOAD`) /// The given content media type returned from an HTTP response is not supported (`SERVICE` and `LOAD`)
#[error("The content media type {0} is not supported")]
UnsupportedContentType(String), UnsupportedContentType(String),
/// The `SERVICE` call has not returns solutions /// The `SERVICE` call has not returns solutions
#[error("The service is not returning solutions but a boolean or a graph")]
ServiceDoesNotReturnSolutions, ServiceDoesNotReturnSolutions,
/// The results are not a RDF graph /// The results are not a RDF graph
#[error("The query results are not a RDF graph")]
NotAGraph, NotAGraph,
} }
impl fmt::Display for EvaluationError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parsing(error) => error.fmt(f),
Self::Storage(error) => error.fmt(f),
Self::GraphParsing(error) => error.fmt(f),
Self::ResultsParsing(error) => error.fmt(f),
Self::ResultsSerialization(error) => error.fmt(f),
Self::Service(error) => error.fmt(f),
Self::GraphAlreadyExists(graph) => write!(f, "The graph {graph} already exists"),
Self::GraphDoesNotExist(graph) => write!(f, "The graph {graph} does not exist"),
Self::UnboundService => {
f.write_str("The variable encoding the service name is unbound")
}
Self::UnsupportedService(service) => {
write!(f, "The service {service} is not supported")
}
Self::UnsupportedContentType(content_type) => {
write!(f, "The content media type {content_type} is not supported")
}
Self::ServiceDoesNotReturnSolutions => {
f.write_str("The service is not returning solutions but a boolean or a graph")
}
Self::NotAGraph => f.write_str("The query results are not a RDF graph"),
}
}
}
impl Error for EvaluationError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Parsing(e) => Some(e),
Self::Storage(e) => Some(e),
Self::GraphParsing(e) => Some(e),
Self::ResultsParsing(e) => Some(e),
Self::ResultsSerialization(e) => Some(e),
Self::Service(e) => {
let e = Box::as_ref(e);
Some(e)
}
Self::GraphAlreadyExists(_)
| Self::GraphDoesNotExist(_)
| Self::UnboundService
| Self::UnsupportedService(_)
| Self::UnsupportedContentType(_)
| Self::ServiceDoesNotReturnSolutions
| Self::NotAGraph => None,
}
}
}
impl From<Infallible> for EvaluationError { impl From<Infallible> for EvaluationError {
#[inline] #[inline]
fn from(error: Infallible) -> Self { fn from(error: Infallible) -> Self {
@ -99,34 +60,6 @@ impl From<Infallible> for EvaluationError {
} }
} }
impl From<ParseError> for EvaluationError {
#[inline]
fn from(error: ParseError) -> Self {
Self::Parsing(error)
}
}
impl From<StorageError> for EvaluationError {
#[inline]
fn from(error: StorageError) -> Self {
Self::Storage(error)
}
}
impl From<RdfParseError> for EvaluationError {
#[inline]
fn from(error: RdfParseError) -> Self {
Self::GraphParsing(error)
}
}
impl From<ResultsParseError> for EvaluationError {
#[inline]
fn from(error: ResultsParseError) -> Self {
Self::ResultsParsing(error)
}
}
impl From<EvaluationError> for io::Error { impl From<EvaluationError> for io::Error {
#[inline] #[inline]
fn from(error: EvaluationError) -> Self { fn from(error: EvaluationError) -> Self {

@ -5,46 +5,20 @@ use std::{fmt, io};
use thiserror::Error; use thiserror::Error;
/// An error related to storage operations (reads, writes...). /// An error related to storage operations (reads, writes...).
#[derive(Debug)] #[derive(Debug, Error)]
#[non_exhaustive] #[non_exhaustive]
pub enum StorageError { pub enum StorageError {
/// Error from the OS I/O layer. /// Error from the OS I/O layer.
Io(io::Error), #[error(transparent)]
Io(#[from] io::Error),
/// Error related to data corruption. /// Error related to data corruption.
Corruption(CorruptionError), #[error(transparent)]
Corruption(#[from] CorruptionError),
#[doc(hidden)] #[doc(hidden)]
#[error(transparent)]
Other(Box<dyn Error + Send + Sync + 'static>), Other(Box<dyn Error + Send + Sync + 'static>),
} }
impl fmt::Display for StorageError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
Self::Corruption(e) => e.fmt(f),
Self::Other(e) => e.fmt(f),
}
}
}
impl Error for StorageError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Corruption(e) => Some(e),
Self::Other(e) => Some(e.as_ref()),
}
}
}
impl From<io::Error> for StorageError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<StorageError> for io::Error { impl From<StorageError> for io::Error {
#[inline] #[inline]
fn from(error: StorageError) -> Self { fn from(error: StorageError) -> Self {
@ -106,13 +80,6 @@ impl Error for CorruptionError {
} }
} }
impl From<CorruptionError> for StorageError {
#[inline]
fn from(error: CorruptionError) -> Self {
Self::Corruption(error)
}
}
impl From<CorruptionError> for io::Error { impl From<CorruptionError> for io::Error {
#[inline] #[inline]
fn from(error: CorruptionError) -> Self { fn from(error: CorruptionError) -> Self {
@ -121,57 +88,25 @@ impl From<CorruptionError> for io::Error {
} }
/// An error raised while loading a file into a [`Store`](crate::store::Store). /// An error raised while loading a file into a [`Store`](crate::store::Store).
#[derive(Debug)] #[derive(Debug, Error)]
pub enum LoaderError { pub enum LoaderError {
/// An error raised while reading the file. /// An error raised while reading the file.
Parsing(ParseError), #[error(transparent)]
Parsing(#[from] ParseError),
/// An error raised during the insertion in the store. /// An error raised during the insertion in the store.
Storage(StorageError), #[error(transparent)]
Storage(#[from] StorageError),
/// The base IRI is invalid. /// The base IRI is invalid.
#[error("Invalid base IRI '{iri}': {error}")]
InvalidBaseIri { InvalidBaseIri {
/// The IRI itself. /// The IRI itself.
iri: String, iri: String,
/// The parsing error. /// The parsing error.
#[source]
error: IriParseError, error: IriParseError,
}, },
} }
impl fmt::Display for LoaderError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parsing(e) => e.fmt(f),
Self::Storage(e) => e.fmt(f),
Self::InvalidBaseIri { iri, error } => write!(f, "Invalid base IRI '{iri}': {error}"),
}
}
}
impl Error for LoaderError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Parsing(e) => Some(e),
Self::Storage(e) => Some(e),
Self::InvalidBaseIri { error, .. } => Some(error),
}
}
}
impl From<ParseError> for LoaderError {
#[inline]
fn from(error: ParseError) -> Self {
Self::Parsing(error)
}
}
impl From<StorageError> for LoaderError {
#[inline]
fn from(error: StorageError) -> Self {
Self::Storage(error)
}
}
impl From<LoaderError> for io::Error { impl From<LoaderError> for io::Error {
#[inline] #[inline]
fn from(error: LoaderError) -> Self { fn from(error: LoaderError) -> Self {

@ -1,10 +1,10 @@
use std::borrow::Borrow; use std::borrow::Borrow;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::error::Error;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::ops::Deref; use std::ops::Deref;
use std::str::{FromStr, Utf8Error}; use std::str::{FromStr, Utf8Error};
use std::{fmt, str}; use std::{fmt, str};
use thiserror::Error;
/// A small inline string /// A small inline string
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
@ -169,31 +169,10 @@ impl<'a> TryFrom<&'a str> for SmallString {
} }
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, Error)]
pub enum BadSmallStringError { pub enum BadSmallStringError {
#[error("small strings could only contain at most 15 characters, found {0}")]
TooLong(usize), TooLong(usize),
BadUtf8(Utf8Error), #[error(transparent)]
} BadUtf8(#[from] Utf8Error),
impl fmt::Display for BadSmallStringError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TooLong(v) => write!(
f,
"small strings could only contain at most 15 characters, found {v}"
),
Self::BadUtf8(e) => e.fmt(f),
}
}
}
impl Error for BadSmallStringError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::TooLong(_) => None,
Self::BadUtf8(e) => Some(e),
}
}
} }

@ -22,6 +22,7 @@ rdf-star = ["oxrdf/rdf-star", "oxttl/rdf-star"]
oxrdf.workspace = true oxrdf.workspace = true
oxrdfxml.workspace = true oxrdfxml.workspace = true
oxttl.workspace = true oxttl.workspace = true
thiserror.workspace = true
tokio = { workspace = true, optional = true, features = ["io-util"] } tokio = { workspace = true, optional = true, features = ["io-util"] }
[dev-dependencies] [dev-dependencies]

@ -1,14 +1,17 @@
use std::error::Error; use std::error::Error;
use std::ops::Range; use std::ops::Range;
use std::{fmt, io}; use std::{fmt, io};
use thiserror::Error;
/// Error returned during RDF format parsing. /// Error returned during RDF format parsing.
#[derive(Debug)] #[derive(Debug, Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
Io(io::Error), #[error(transparent)]
Io(#[from] io::Error),
/// An error in the file syntax. /// An error in the file syntax.
Syntax(SyntaxError), #[error(transparent)]
Syntax(#[from] SyntaxError),
} }
impl ParseError { impl ParseError {
@ -19,26 +22,6 @@ impl ParseError {
} }
} }
impl fmt::Display for ParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
Self::Syntax(e) => e.fmt(f),
}
}
}
impl Error for ParseError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Syntax(e) => Some(e),
}
}
}
impl From<oxttl::SyntaxError> for SyntaxError { impl From<oxttl::SyntaxError> for SyntaxError {
#[inline] #[inline]
fn from(error: oxttl::SyntaxError) -> Self { fn from(error: oxttl::SyntaxError) -> Self {
@ -77,20 +60,6 @@ impl From<oxrdfxml::ParseError> for ParseError {
} }
} }
impl From<io::Error> for ParseError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<SyntaxError> for ParseError {
#[inline]
fn from(error: SyntaxError) -> Self {
Self::Syntax(error)
}
}
impl From<ParseError> for io::Error { impl From<ParseError> for io::Error {
#[inline] #[inline]
fn from(error: ParseError) -> Self { fn from(error: ParseError) -> Self {

@ -22,6 +22,7 @@ oxilangtag.workspace = true
oxiri.workspace = true oxiri.workspace = true
oxrdf.workspace = true oxrdf.workspace = true
quick-xml.workspace = true quick-xml.workspace = true
thiserror.workspace = true
tokio = { workspace = true, optional = true, features = ["io-util"] } tokio = { workspace = true, optional = true, features = ["io-util"] }
[dev-dependencies] [dev-dependencies]

@ -3,48 +3,17 @@ use oxiri::IriParseError;
use std::error::Error; use std::error::Error;
use std::sync::Arc; use std::sync::Arc;
use std::{fmt, io}; use std::{fmt, io};
use thiserror::Error;
/// Error returned during RDF/XML parsing. /// Error returned during RDF/XML parsing.
#[derive(Debug)] #[derive(Debug, Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
Io(io::Error), #[error(transparent)]
Io(#[from] io::Error),
/// An error in the file syntax. /// An error in the file syntax.
Syntax(SyntaxError), #[error(transparent)]
} Syntax(#[from] SyntaxError),
impl fmt::Display for ParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
Self::Syntax(e) => e.fmt(f),
}
}
}
impl Error for ParseError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Syntax(e) => Some(e),
}
}
}
impl From<io::Error> for ParseError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<SyntaxError> for ParseError {
#[inline]
fn from(error: SyntaxError) -> Self {
Self::Syntax(error)
}
} }
impl From<ParseError> for io::Error { impl From<ParseError> for io::Error {

@ -23,6 +23,7 @@ memchr.workspace = true
oxrdf.workspace = true oxrdf.workspace = true
oxiri.workspace = true oxiri.workspace = true
oxilangtag.workspace = true oxilangtag.workspace = true
thiserror.workspace = true
tokio = { workspace = true, optional = true, features = ["io-util"] } tokio = { workspace = true, optional = true, features = ["io-util"] }
[dev-dependencies] [dev-dependencies]

@ -1,6 +1,7 @@
use std::error::Error; use std::error::Error;
use std::ops::Range; use std::ops::Range;
use std::{fmt, io}; use std::{fmt, io};
use thiserror::Error;
/// A position in a text i.e. a `line` number starting from 0, a `column` number starting from 0 (in number of code points) and a global file `offset` starting from 0 (in number of bytes). /// A position in a text i.e. a `line` number starting from 0, a `column` number starting from 0 (in number of code points) and a global file `offset` starting from 0 (in number of bytes).
#[derive(Eq, PartialEq, Debug, Clone, Copy)] #[derive(Eq, PartialEq, Debug, Clone, Copy)]
@ -79,46 +80,14 @@ impl From<SyntaxError> for io::Error {
/// A parsing error. /// A parsing error.
/// ///
/// It is the union of [`SyntaxError`] and [`io::Error`]. /// It is the union of [`SyntaxError`] and [`io::Error`].
#[derive(Debug)] #[derive(Debug, Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
Io(io::Error), #[error(transparent)]
Io(#[from] io::Error),
/// An error in the file syntax. /// An error in the file syntax.
Syntax(SyntaxError), #[error(transparent)]
} Syntax(#[from] SyntaxError),
impl fmt::Display for ParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
Self::Syntax(e) => e.fmt(f),
}
}
}
impl Error for ParseError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(match self {
Self::Io(e) => e,
Self::Syntax(e) => e,
})
}
}
impl From<SyntaxError> for ParseError {
#[inline]
fn from(error: SyntaxError) -> Self {
Self::Syntax(error)
}
}
impl From<io::Error> for ParseError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
} }
impl From<ParseError> for io::Error { impl From<ParseError> for io::Error {

@ -23,6 +23,7 @@ json-event-parser.workspace = true
memchr.workspace = true memchr.workspace = true
oxrdf.workspace = true oxrdf.workspace = true
quick-xml.workspace = true quick-xml.workspace = true
thiserror.workspace = true
tokio = { workspace = true, optional = true, features = ["io-util"] } tokio = { workspace = true, optional = true, features = ["io-util"] }
[dev-dependencies] [dev-dependencies]

@ -3,48 +3,17 @@ use std::error::Error;
use std::ops::Range; use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
use std::{fmt, io}; use std::{fmt, io};
use thiserror::Error;
/// Error returned during SPARQL result formats format parsing. /// Error returned during SPARQL result formats format parsing.
#[derive(Debug)] #[derive(Debug, Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
Io(io::Error), #[error(transparent)]
Io(#[from] io::Error),
/// An error in the file syntax. /// An error in the file syntax.
Syntax(SyntaxError), #[error(transparent)]
} Syntax(#[from] SyntaxError),
impl fmt::Display for ParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
Self::Syntax(e) => e.fmt(f),
}
}
}
impl Error for ParseError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Syntax(e) => Some(e),
}
}
}
impl From<io::Error> for ParseError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<SyntaxError> for ParseError {
#[inline]
fn from(error: SyntaxError) -> Self {
Self::Syntax(error)
}
} }
impl From<ParseError> for io::Error { impl From<ParseError> for io::Error {

Loading…
Cancel
Save