pull/775/head
Yuri Astrakhan 1 year ago
parent a7a39914fe
commit 9beb3f6297
  1. 4
      lib/oxigraph/src/storage/error.rs
  2. 15
      lib/oxrdfxml/src/error.rs
  3. 20
      lib/oxrdfxml/src/parser.rs

@ -55,13 +55,13 @@ impl CorruptionError {
#[inline] #[inline]
pub(crate) fn from_encoded_term(encoded: &EncodedTerm, term: &TermRef<'_>) -> Self { pub(crate) fn from_encoded_term(encoded: &EncodedTerm, term: &TermRef<'_>) -> Self {
// TODO: eventually use a dedicated error enum value // TODO: eventually use a dedicated error enum value
Self::new(format!("Invalid term encoding {encoded:?} for {term}")) Self::msg(format!("Invalid term encoding {encoded:?} for {term}"))
} }
#[inline] #[inline]
pub(crate) fn from_missing_column_family_name(name: &'static str) -> Self { pub(crate) fn from_missing_column_family_name(name: &'static str) -> Self {
// TODO: eventually use a dedicated error enum value // TODO: eventually use a dedicated error enum value
Self::new(format!("Column family {name} does not exist")) Self::msg(format!("Column family {name} does not exist"))
} }
/// Builds an error from a printable error message. /// Builds an error from a printable error message.

@ -31,9 +31,7 @@ impl From<quick_xml::Error> for ParseError {
quick_xml::Error::Io(error) => { quick_xml::Error::Io(error) => {
Self::Io(Arc::try_unwrap(error).unwrap_or_else(|e| io::Error::new(e.kind(), e))) Self::Io(Arc::try_unwrap(error).unwrap_or_else(|e| io::Error::new(e.kind(), e)))
} }
_ => Self::Syntax(SyntaxError { _ => Self::Syntax(SyntaxError(SyntaxErrorKind::Xml(error))),
inner: SyntaxErrorKind::Xml(error),
}),
} }
} }
} }
@ -41,10 +39,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, thiserror::Error)] #[derive(Debug, thiserror::Error)]
#[error(transparent)] #[error(transparent)]
pub struct SyntaxError { pub struct SyntaxError(#[from] pub(crate) SyntaxErrorKind);
#[from]
pub(crate) inner: SyntaxErrorKind,
}
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum SyntaxErrorKind { pub enum SyntaxErrorKind {
@ -70,16 +65,14 @@ impl SyntaxError {
/// Builds an error from a printable error message. /// Builds an error from a printable error message.
#[inline] #[inline]
pub(crate) fn msg(msg: impl Into<String>) -> Self { pub(crate) fn msg(msg: impl Into<String>) -> Self {
Self { Self(SyntaxErrorKind::Msg(msg.into()))
inner: SyntaxErrorKind::Msg(msg.into()),
}
} }
} }
impl From<SyntaxError> for io::Error { impl From<SyntaxError> for io::Error {
#[inline] #[inline]
fn from(error: SyntaxError) -> Self { fn from(error: SyntaxError) -> Self {
match error.inner { match error.0 {
SyntaxErrorKind::Xml(error) => match error { SyntaxErrorKind::Xml(error) => match error {
quick_xml::Error::Io(error) => { quick_xml::Error::Io(error) => {
Arc::try_unwrap(error).unwrap_or_else(|e| Self::new(e.kind(), e)) Arc::try_unwrap(error).unwrap_or_else(|e| Self::new(e.kind(), e))

@ -575,8 +575,8 @@ impl<R> RdfXmlReader<R> {
tag tag
} else { } else {
LanguageTag::parse(tag.to_ascii_lowercase()) LanguageTag::parse(tag.to_ascii_lowercase())
.map_err(|error| SyntaxError { .map_err(|error| {
inner: SyntaxErrorKind::InvalidLanguageTag { tag, error }, SyntaxError(SyntaxErrorKind::InvalidLanguageTag { tag, error })
})? })?
.into_inner() .into_inner()
}); });
@ -588,9 +588,7 @@ impl<R> RdfXmlReader<R> {
} else { } else {
Iri::parse(iri.clone()) Iri::parse(iri.clone())
} }
.map_err(|error| SyntaxError { .map_err(|error| SyntaxError(SyntaxErrorKind::InvalidIri { iri, error }))?,
inner: SyntaxErrorKind::InvalidIri { iri, error },
})?,
) )
} else { } else {
// We ignore other xml attributes // We ignore other xml attributes
@ -1169,11 +1167,11 @@ impl<R> RdfXmlReader<R> {
} else { } else {
base_iri.resolve(&relative_iri) base_iri.resolve(&relative_iri)
} }
.map_err(|error| SyntaxError { .map_err(|error| {
inner: SyntaxErrorKind::InvalidIri { SyntaxError(SyntaxErrorKind::InvalidIri {
iri: relative_iri, iri: relative_iri,
error, error,
}, })
})? })?
.into_inner(), .into_inner(),
)) ))
@ -1187,11 +1185,11 @@ impl<R> RdfXmlReader<R> {
relative_iri relative_iri
} else { } else {
Iri::parse(relative_iri.clone()) Iri::parse(relative_iri.clone())
.map_err(|error| SyntaxError { .map_err(|error| {
inner: SyntaxErrorKind::InvalidIri { SyntaxError(SyntaxErrorKind::InvalidIri {
iri: relative_iri, iri: relative_iri,
error, error,
}, })
})? })?
.into_inner() .into_inner()
})) }))

Loading…
Cancel
Save