a few more cleanups

pull/745/head
Yuri Astrakhan 11 months ago
parent a62c5102c4
commit 487f61f704
  1. 3
      lib/oxigraph/src/sparql/error.rs
  2. 9
      lib/oxigraph/src/storage/error.rs
  3. 3
      lib/oxigraph/src/storage/small_string.rs
  4. 13
      lib/oxrdf/src/blank_node.rs
  5. 3
      lib/oxrdf/src/parser.rs
  6. 13
      lib/oxrdf/src/variable.rs
  7. 5
      lib/oxrdfio/src/error.rs
  8. 5
      lib/oxrdfxml/src/error.rs
  9. 21
      lib/oxsdatatypes/src/date_time.rs
  10. 3
      lib/oxsdatatypes/src/decimal.rs
  11. 35
      lib/oxsdatatypes/src/duration.rs
  12. 8
      lib/oxttl/src/toolkit/error.rs
  13. 5
      lib/sparesults/src/error.rs
  14. 3
      lib/spargebra/src/parser.rs

@ -6,10 +6,9 @@ use crate::storage::StorageError;
use std::convert::Infallible; use std::convert::Infallible;
use std::error::Error; use std::error::Error;
use std::io; use std::io;
use thiserror::Error;
/// A SPARQL evaluation error. /// A SPARQL evaluation error.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
#[non_exhaustive] #[non_exhaustive]
pub enum EvaluationError { pub enum EvaluationError {
/// An error in SPARQL parsing. /// An error in SPARQL parsing.

@ -2,10 +2,9 @@ use crate::io::{ParseError, RdfFormat};
use oxiri::IriParseError; use oxiri::IriParseError;
use std::error::Error; use std::error::Error;
use std::io; use std::io;
use thiserror::Error;
/// An error related to storage operations (reads, writes...). /// An error related to storage operations (reads, writes...).
#[derive(Debug, Error)] #[derive(Debug, thiserror::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.
@ -31,7 +30,7 @@ impl From<StorageError> for io::Error {
} }
/// An error return if some content in the database is corrupted. /// An error return if some content in the database is corrupted.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum CorruptionError { pub enum CorruptionError {
#[error("{0}")] #[error("{0}")]
Msg(String), Msg(String),
@ -61,7 +60,7 @@ 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, Error)] #[derive(Debug, thiserror::Error)]
pub enum LoaderError { pub enum LoaderError {
/// An error raised while reading the file. /// An error raised while reading the file.
#[error(transparent)] #[error(transparent)]
@ -94,7 +93,7 @@ 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, Error)] #[derive(Debug, thiserror::Error)]
pub enum SerializerError { pub enum SerializerError {
/// An error raised while writing the content. /// An error raised while writing the content.
#[error(transparent)] #[error(transparent)]

@ -4,7 +4,6 @@ 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,7 +168,7 @@ impl<'a> TryFrom<&'a str> for SmallString {
} }
} }
#[derive(Debug, Clone, Copy, Error)] #[derive(Debug, Clone, Copy, thiserror::Error)]
pub enum BadSmallStringError { pub enum BadSmallStringError {
#[error("small strings could only contain at most 15 characters, found {0}")] #[error("small strings could only contain at most 15 characters, found {0}")]
TooLong(usize), TooLong(usize),

@ -1,5 +1,4 @@
use rand::random; use rand::random;
use std::error::Error;
use std::io::Write; use std::io::Write;
use std::{fmt, str}; use std::{fmt, str};
@ -345,18 +344,10 @@ fn to_integer_id(id: &str) -> Option<u128> {
} }
/// An error raised during [`BlankNode`] IDs validation. /// An error raised during [`BlankNode`] IDs validation.
#[derive(Debug)] #[derive(Debug, thiserror::Error)]
#[error("The blank node identifier is invalid")]
pub struct BlankNodeIdParseError; pub struct BlankNodeIdParseError;
impl fmt::Display for BlankNodeIdParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("The blank node identifier is invalid")
}
}
impl Error for BlankNodeIdParseError {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::panic_in_result_fn)] #![allow(clippy::panic_in_result_fn)]

@ -7,7 +7,6 @@ use crate::{
use crate::{Subject, Triple}; use crate::{Subject, Triple};
use std::char; use std::char;
use std::str::{Chars, FromStr}; use std::str::{Chars, FromStr};
use thiserror::Error;
/// This limit is set in order to avoid stack overflow error when parsing nested triples due to too many recursive calls. /// This limit is set in order to avoid stack overflow error when parsing nested triples due to too many recursive calls.
/// The actual limit value is a wet finger compromise between not failing to parse valid files and avoiding to trigger stack overflow errors. /// The actual limit value is a wet finger compromise between not failing to parse valid files and avoiding to trigger stack overflow errors.
@ -413,7 +412,7 @@ fn read_hexa_char(input: &mut Chars<'_>, len: usize) -> Result<char, TermParseEr
} }
/// An error raised during term serialization parsing using the [`FromStr`] trait. /// An error raised during term serialization parsing using the [`FromStr`] trait.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum TermParseError { pub enum TermParseError {
#[error("Error while parsing the named node '{value}': {error}")] #[error("Error while parsing the named node '{value}': {error}")]
Iri { error: IriParseError, value: String }, Iri { error: IriParseError, value: String },

@ -1,5 +1,4 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use std::error::Error;
use std::fmt; use std::fmt;
/// A [SPARQL query](https://www.w3.org/TR/sparql11-query/) owned variable. /// A [SPARQL query](https://www.w3.org/TR/sparql11-query/) owned variable.
@ -212,14 +211,6 @@ fn validate_variable_identifier(id: &str) -> Result<(), VariableNameParseError>
} }
/// An error raised during [`Variable`] name validation. /// An error raised during [`Variable`] name validation.
#[derive(Debug)] #[derive(Debug, thiserror::Error)]
#[error("The variable name is invalid")]
pub struct VariableNameParseError; pub struct VariableNameParseError;
impl fmt::Display for VariableNameParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("The variable name is invalid")
}
}
impl Error for VariableNameParseError {}

@ -1,9 +1,8 @@
use std::io; use std::io;
use std::ops::Range; use std::ops::Range;
use thiserror::Error;
/// Error returned during RDF format parsing. /// Error returned during RDF format parsing.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
#[error(transparent)] #[error(transparent)]
@ -50,7 +49,7 @@ impl From<ParseError> for io::Error {
} }
/// An error in the syntax of the parsed file. /// An error in the syntax of the parsed file.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum SyntaxError { pub enum SyntaxError {
#[error(transparent)] #[error(transparent)]
Turtle(#[from] oxttl::SyntaxError), Turtle(#[from] oxttl::SyntaxError),

@ -2,10 +2,9 @@ use oxilangtag::LanguageTagParseError;
use oxiri::IriParseError; use oxiri::IriParseError;
use std::io; use std::io;
use std::sync::Arc; use std::sync::Arc;
use thiserror::Error;
/// Error returned during RDF/XML parsing. /// Error returned during RDF/XML parsing.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
#[error(transparent)] #[error(transparent)]
@ -38,7 +37,7 @@ impl From<quick_xml::Error> for ParseError {
} }
/// An error in the syntax of the parsed file. /// An error in the syntax of the parsed file.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum SyntaxError { pub enum SyntaxError {
#[error(transparent)] #[error(transparent)]
Xml(#[from] quick_xml::Error), Xml(#[from] quick_xml::Error),

@ -6,7 +6,6 @@ use std::error::Error;
use std::fmt; use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::str::FromStr; use std::str::FromStr;
use thiserror::Error;
/// [XML Schema `dateTime` datatype](https://www.w3.org/TR/xmlschema11-2/#dateTime) /// [XML Schema `dateTime` datatype](https://www.w3.org/TR/xmlschema11-2/#dateTime)
/// ///
@ -2040,7 +2039,7 @@ fn time_on_timeline(props: &DateTimeSevenPropertyModel) -> Option<Decimal> {
} }
/// A parsing error /// A parsing error
#[derive(Debug, Clone, Error)] #[derive(Debug, Clone, thiserror::Error)]
pub enum ParseDateTimeError { pub enum ParseDateTimeError {
#[error("{day} is not a valid day of {month}")] #[error("{day} is not a valid day of {month}")]
InvalidDayOfMonth { day: u8, month: u8 }, InvalidDayOfMonth { day: u8, month: u8 },
@ -2402,24 +2401,14 @@ impl Error for DateTimeOverflowError {}
/// The value provided as timezone is not valid. /// The value provided as timezone is not valid.
/// ///
/// Matches XPath [`FODT0003` error](https://www.w3.org/TR/xpath-functions-31/#ERRFODT0003). /// Matches XPath [`FODT0003` error](https://www.w3.org/TR/xpath-functions-31/#ERRFODT0003).
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, thiserror::Error)]
#[error("invalid timezone offset {}:{}",
self.offset_in_minutes / 60,
self.offset_in_minutes.abs() % 60)]
pub struct InvalidTimezoneError { pub struct InvalidTimezoneError {
offset_in_minutes: i64, offset_in_minutes: i64,
} }
impl fmt::Display for InvalidTimezoneError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"invalid timezone offset {}:{}",
self.offset_in_minutes / 60,
self.offset_in_minutes.abs() % 60
)
}
}
impl Error for InvalidTimezoneError {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#![allow(clippy::panic_in_result_fn)] #![allow(clippy::panic_in_result_fn)]

@ -3,7 +3,6 @@ use std::error::Error;
use std::fmt; use std::fmt;
use std::fmt::Write; use std::fmt::Write;
use std::str::FromStr; use std::str::FromStr;
use thiserror::Error;
const DECIMAL_PART_DIGITS: u32 = 18; const DECIMAL_PART_DIGITS: u32 = 18;
const DECIMAL_PART_POW: i128 = 1_000_000_000_000_000_000; const DECIMAL_PART_POW: i128 = 1_000_000_000_000_000_000;
@ -610,7 +609,7 @@ impl fmt::Display for Decimal {
} }
/// An error when parsing a [`Decimal`]. /// An error when parsing a [`Decimal`].
#[derive(Debug, Clone, Error)] #[derive(Debug, Clone, thiserror::Error)]
pub enum ParseDecimalError { pub enum ParseDecimalError {
#[error("Value overflow")] #[error("Value overflow")]
Overflow, Overflow,

@ -1,6 +1,5 @@
use crate::{DateTime, Decimal}; use crate::{DateTime, Decimal};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::error::Error;
use std::fmt; use std::fmt;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration as StdDuration; use std::time::Duration as StdDuration;
@ -937,7 +936,8 @@ fn decimal_prefix(input: &str) -> (&str, &str) {
} }
/// A parsing error /// A parsing error
#[derive(Debug, Clone)] #[derive(Debug, Clone, thiserror::Error)]
#[error("{msg}")]
pub struct ParseDurationError { pub struct ParseDurationError {
msg: &'static str, msg: &'static str,
} }
@ -946,46 +946,24 @@ const OVERFLOW_ERROR: ParseDurationError = ParseDurationError {
msg: "Overflow error", msg: "Overflow error",
}; };
impl fmt::Display for ParseDurationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.msg)
}
}
impl ParseDurationError { impl ParseDurationError {
const fn msg(msg: &'static str) -> Self { const fn msg(msg: &'static str) -> Self {
Self { msg } Self { msg }
} }
} }
impl Error for ParseDurationError {}
/// An overflow during [`Duration`]-related operations. /// An overflow during [`Duration`]-related operations.
/// ///
/// Matches XPath [`FODT0002` error](https://www.w3.org/TR/xpath-functions-31/#ERRFODT0002). /// Matches XPath [`FODT0002` error](https://www.w3.org/TR/xpath-functions-31/#ERRFODT0002).
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, thiserror::Error)]
#[error("overflow during xsd:duration computation")]
pub struct DurationOverflowError; pub struct DurationOverflowError;
impl fmt::Display for DurationOverflowError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("overflow during xsd:duration computation")
}
}
impl Error for DurationOverflowError {}
/// The year-month and the day-time components of a [`Duration`] have an opposite sign. /// The year-month and the day-time components of a [`Duration`] have an opposite sign.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, thiserror::Error)]
#[error("The xsd:yearMonthDuration and xsd:dayTimeDuration components of a xsd:duration can't have opposite sign")]
pub struct OppositeSignInDurationComponentsError; pub struct OppositeSignInDurationComponentsError;
impl fmt::Display for OppositeSignInDurationComponentsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("The xsd:yearMonthDuration and xsd:dayTimeDuration components of a xsd:duration can't have opposite sign")
}
}
impl Error for OppositeSignInDurationComponentsError {}
impl From<OppositeSignInDurationComponentsError> for ParseDurationError { impl From<OppositeSignInDurationComponentsError> for ParseDurationError {
#[inline] #[inline]
fn from(_: OppositeSignInDurationComponentsError) -> Self { fn from(_: OppositeSignInDurationComponentsError) -> Self {
@ -1000,6 +978,7 @@ mod tests {
#![allow(clippy::panic_in_result_fn)] #![allow(clippy::panic_in_result_fn)]
use super::*; use super::*;
use std::error::Error;
#[test] #[test]
fn from_str() -> Result<(), ParseDurationError> { fn from_str() -> Result<(), ParseDurationError> {

@ -1,7 +1,5 @@
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)]
@ -14,7 +12,7 @@ pub struct TextPosition {
/// An error in the syntax of the parsed file. /// An error in the syntax of the parsed file.
/// ///
/// It is composed of a message and a byte range in the input. /// It is composed of a message and a byte range in the input.
#[derive(Debug)] #[derive(Debug, thiserror::Error)]
pub struct SyntaxError { pub struct SyntaxError {
pub(super) location: Range<TextPosition>, pub(super) location: Range<TextPosition>,
pub(super) message: String, pub(super) message: String,
@ -68,8 +66,6 @@ impl fmt::Display for SyntaxError {
} }
} }
impl Error for SyntaxError {}
impl From<SyntaxError> for io::Error { impl From<SyntaxError> for io::Error {
#[inline] #[inline]
fn from(error: SyntaxError) -> Self { fn from(error: SyntaxError) -> Self {
@ -80,7 +76,7 @@ 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, Error)] #[derive(Debug, thiserror::Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
#[error(transparent)] #[error(transparent)]

@ -2,10 +2,9 @@ use oxrdf::TermParseError;
use std::io; use std::io;
use std::ops::Range; use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
use thiserror::Error;
/// Error returned during SPARQL result formats format parsing. /// Error returned during SPARQL result formats format parsing.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum ParseError { pub enum ParseError {
/// I/O error during parsing (file not found...). /// I/O error during parsing (file not found...).
#[error(transparent)] #[error(transparent)]
@ -47,7 +46,7 @@ impl From<quick_xml::Error> for ParseError {
} }
/// An error in the syntax of the parsed file. /// An error in the syntax of the parsed file.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum SyntaxError { pub enum SyntaxError {
#[error(transparent)] #[error(transparent)]
Json(#[from] json_event_parser::SyntaxError), Json(#[from] json_event_parser::SyntaxError),

@ -13,7 +13,6 @@ use std::char;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::mem::take; use std::mem::take;
use std::str::FromStr; use std::str::FromStr;
use thiserror::Error;
/// Parses a SPARQL query with an optional base IRI to resolve relative IRIs in the query. /// Parses a SPARQL query with an optional base IRI to resolve relative IRIs in the query.
pub fn parse_query(query: &str, base_iri: Option<&str>) -> Result<Query, ParseError> { pub fn parse_query(query: &str, base_iri: Option<&str>) -> Result<Query, ParseError> {
@ -32,7 +31,7 @@ pub fn parse_update(update: &str, base_iri: Option<&str>) -> Result<Update, Pars
} }
/// Error returned during SPARQL parsing. /// Error returned during SPARQL parsing.
#[derive(Debug, Error)] #[derive(Debug, thiserror::Error)]
pub enum ParseError { pub enum ParseError {
#[error("Invalid SPARQL base IRI provided: {0}")] #[error("Invalid SPARQL base IRI provided: {0}")]
InvalidBaseIri(#[from] IriParseError), InvalidBaseIri(#[from] IriParseError),

Loading…
Cancel
Save