xml: Some work on errors

This commit is contained in:
Lennart
2025-02-06 14:06:17 +01:00
parent 9b6ad4eb39
commit 6caa04a516
9 changed files with 37 additions and 33 deletions

View File

@@ -67,6 +67,7 @@ impl<T: XmlRootTag + XmlDeserialize> XmlDocument for T {
return Self::deserialize(&mut reader, &start, empty);
}
Event::Eof => return Err(XmlError::Eof),
_ => return Err(XmlError::UnsupportedEvent("unknown, todo")),
};
}

View File

@@ -4,22 +4,23 @@ use thiserror::Error;
#[derive(Debug, Error)]
pub enum XmlError {
// Syntactix errors
#[error(transparent)]
QuickXmlError(#[from] quick_xml::Error),
#[error(transparent)]
QuickXmlAttrError(#[from] quick_xml::events::attributes::AttrError),
#[error(transparent)]
FromUtf8Error(#[from] FromUtf8Error),
#[error("Invalid tag [{0}]{1}. Expected [{2}]{3}")]
InvalidTag(String, String, String, String),
#[error("Missing field {0}")]
MissingField(&'static str),
#[error("End of file, expected closing tags")]
Eof,
#[error("Unsupported xml event: {0}")]
UnsupportedEvent(&'static str),
#[error("{0}")]
Other(String),
// Semantic errors
#[error("Invalid tag [{0}]{1}. Expected [{2}]{3}")]
InvalidTag(String, String, String, String),
#[error("Missing field {0}")]
MissingField(&'static str),
#[error("Invalid variant: {0}")]
InvalidVariant(String),
#[error("Invalid field name in {0}: {1}")]

View File

@@ -22,6 +22,8 @@ pub enum ParseValueError {
ParseIntError(#[from] ParseIntError),
#[error(transparent)]
ParseFloatError(#[from] ParseFloatError),
#[error("{0}")]
Other(String),
}
macro_rules! impl_value_parse {