mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
xml: Some work on errors
This commit is contained in:
@@ -165,7 +165,6 @@ impl Enum {
|
||||
Event::Start(start) | Event::Empty(start) => {
|
||||
return <Self as ::rustical_xml::XmlDeserialize>::deserialize(&mut reader, &start, empty);
|
||||
}
|
||||
|
||||
Event::Eof => return Err(::rustical_xml::XmlError::Eof),
|
||||
Event::Text(bytes_text) => {
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Text"));
|
||||
@@ -173,19 +172,14 @@ impl Enum {
|
||||
Event::CData(cdata) => {
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("CDATA"));
|
||||
}
|
||||
Event::Decl(_) => { /* <?xml ... ?> ignore this */ }
|
||||
Event::Comment(_) => { /* ignore */ }
|
||||
Event::Decl(_) => {
|
||||
/* ignore */
|
||||
// return Err(::rustical_xml::XmlError::UnsupportedEvent("Declaration"));
|
||||
}
|
||||
Event::DocType(_) => { /* ignore */ }
|
||||
Event::PI(_) => {
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Processing instruction"));
|
||||
}
|
||||
Event::DocType(doctype) => {
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Doctype in the middle of the document"));
|
||||
}
|
||||
Event::End(end) => {
|
||||
return Err(::rustical_xml::XmlError::UnsupportedEvent("Premature end"));
|
||||
unreachable!("Premature end of xml document, should be handled by quick_xml");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -179,22 +179,15 @@ impl NamedStruct {
|
||||
let text = String::from_utf8(cdata.to_vec())?;
|
||||
#(#text_field_branches)*
|
||||
}
|
||||
Event::Decl(_) => { /* <?xml ... ?> ignore this */ }
|
||||
Event::Comment(_) => { /* ignore */ }
|
||||
Event::Decl(_) => {
|
||||
// Error: not supported
|
||||
return Err(XmlError::UnsupportedEvent("Declaration"));
|
||||
}
|
||||
Event::DocType(_) => { /* ignore */ }
|
||||
Event::PI(_) => {
|
||||
// Error: not supported
|
||||
return Err(XmlError::UnsupportedEvent("Processing instruction"));
|
||||
}
|
||||
Event::DocType(doctype) => {
|
||||
// Error: start of new document
|
||||
return Err(XmlError::UnsupportedEvent("Doctype in the middle of the document"));
|
||||
}
|
||||
Event::End(end) => {
|
||||
// This should actually be unreachable
|
||||
return Err(XmlError::Other("Unexpected closing tag for wrong element".to_owned()));
|
||||
unreachable!("Unexpected closing tag for wrong element, should be handled by quick_xml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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}")]
|
||||
|
||||
@@ -22,6 +22,8 @@ pub enum ParseValueError {
|
||||
ParseIntError(#[from] ParseIntError),
|
||||
#[error(transparent)]
|
||||
ParseFloatError(#[from] ParseFloatError),
|
||||
#[error("{0}")]
|
||||
Other(String),
|
||||
}
|
||||
|
||||
macro_rules! impl_value_parse {
|
||||
|
||||
Reference in New Issue
Block a user