Improve error message on unexpected root element

This commit is contained in:
Dirkjan Ochtman 2023-02-17 12:31:35 +01:00
parent 88c52e98d2
commit 60898cdf16
2 changed files with 8 additions and 5 deletions

View File

@ -58,10 +58,13 @@ pub fn from_str<'xml, T: FromXml<'xml>>(input: &'xml str) -> Result<T, Error> {
let id = context.element_id(&root)?;
if !T::matches(id, None) {
return Err(Error::UnexpectedValue(format!(
"unexpected root element {} in namespace {}",
return Err(Error::UnexpectedValue(match id.ns.is_empty() {
true => format!("unexpected root element {:?}", id.name),
false => format!(
"unexpected root element {:?} in namespace {:?}",
id.name, id.ns
)));
),
}));
}
let mut value = None;

View File

@ -40,7 +40,7 @@ fn default_namespaces() {
"<NestedDe xmlns=\"WRONG\" xmlns:bar=\"BAZ\"><bar:flag>true</bar:flag></NestedDe>"
),
Err::<NestedDe, _>(Error::UnexpectedValue(
"unexpected root element NestedDe in namespace WRONG".to_owned()
"unexpected root element \"NestedDe\" in namespace \"WRONG\"".to_owned()
))
);