Improve error message on unexpected root element
This commit is contained in:
parent
88c52e98d2
commit
60898cdf16
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
))
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue