From 9beb3f6297befc583e67a665f21188122ac87acc Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Sat, 10 Feb 2024 09:46:13 -0500 Subject: [PATCH] feedback --- lib/oxigraph/src/storage/error.rs | 4 ++-- lib/oxrdfxml/src/error.rs | 15 ++++----------- lib/oxrdfxml/src/parser.rs | 20 +++++++++----------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/oxigraph/src/storage/error.rs b/lib/oxigraph/src/storage/error.rs index 6e4b108f..f2f27cdb 100644 --- a/lib/oxigraph/src/storage/error.rs +++ b/lib/oxigraph/src/storage/error.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. diff --git a/lib/oxrdfxml/src/error.rs b/lib/oxrdfxml/src/error.rs index b4b4bf1f..abc7c55c 100644 --- a/lib/oxrdfxml/src/error.rs +++ b/lib/oxrdfxml/src/error.rs @@ -31,9 +31,7 @@ impl From 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 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) -> Self { - Self { - inner: SyntaxErrorKind::Msg(msg.into()), - } + Self(SyntaxErrorKind::Msg(msg.into())) } } impl From 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)) diff --git a/lib/oxrdfxml/src/parser.rs b/lib/oxrdfxml/src/parser.rs index a4e35784..a952ad02 100644 --- a/lib/oxrdfxml/src/parser.rs +++ b/lib/oxrdfxml/src/parser.rs @@ -575,8 +575,8 @@ impl RdfXmlReader { 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 RdfXmlReader { } 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 RdfXmlReader { } 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 RdfXmlReader { 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() }))