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]
pub(crate) fn from_encoded_term(encoded: &EncodedTerm, term: &TermRef<'_>) -> Self {
// 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]
pub(crate) fn from_missing_column_family_name(name: &'static str) -> Self {
// 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.

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

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

Loading…
Cancel
Save