mirror of
https://github.com/instant-labs/instant-xml.git
synced 2025-02-16 06:52:15 +00:00
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)?;
|
let id = context.element_id(&root)?;
|
||||||
|
|
||||||
if !T::matches(id, None) {
|
if !T::matches(id, None) {
|
||||||
return Err(Error::UnexpectedValue(format!(
|
return Err(Error::UnexpectedValue(match id.ns.is_empty() {
|
||||||
"unexpected root element {} in namespace {}",
|
true => format!("unexpected root element {:?}", id.name),
|
||||||
id.name, id.ns
|
false => format!(
|
||||||
)));
|
"unexpected root element {:?} in namespace {:?}",
|
||||||
|
id.name, id.ns
|
||||||
|
),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut value = None;
|
let mut value = None;
|
||||||
|
@ -40,7 +40,7 @@ fn default_namespaces() {
|
|||||||
"<NestedDe xmlns=\"WRONG\" xmlns:bar=\"BAZ\"><bar:flag>true</bar:flag></NestedDe>"
|
"<NestedDe xmlns=\"WRONG\" xmlns:bar=\"BAZ\"><bar:flag>true</bar:flag></NestedDe>"
|
||||||
),
|
),
|
||||||
Err::<NestedDe, _>(Error::UnexpectedValue(
|
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
Block a user