Improve error reporting for missing values
This commit is contained in:
parent
f6a9d66288
commit
69eca9c2a5
|
@ -63,7 +63,7 @@ fn deserialize_scalar_enum(
|
|||
|
||||
let value = match deserializer.take_str() {
|
||||
#variants
|
||||
_ => return Err(Error::UnexpectedValue),
|
||||
_ => return Err(Error::UnexpectedValue("enum variant not found")),
|
||||
};
|
||||
|
||||
*into = Some(value);
|
||||
|
|
|
@ -25,7 +25,7 @@ impl<'xml, T: FromStr> FromXml<'xml> for FromXmlStr<T> {
|
|||
*into = Some(FromXmlStr(value));
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => Err(Error::UnexpectedValue),
|
||||
Err(_) => Err(Error::UnexpectedValue("unable to parse value")),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,9 @@ impl<'xml> FromXml<'xml> for &'xml str {
|
|||
*into = Some(s);
|
||||
Ok(())
|
||||
}
|
||||
Some(Cow::Owned(_)) => Err(Error::UnexpectedValue),
|
||||
Some(Cow::Owned(_)) => Err(Error::UnexpectedValue(
|
||||
"string with escape characters cannot be deserialized as &str",
|
||||
)),
|
||||
None => Err(Error::MissingValue(&Kind::Scalar)),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn from_str<'xml, T: FromXml<'xml>>(input: &'xml str) -> Result<T, Error> {
|
|||
};
|
||||
|
||||
if id != expected {
|
||||
return Err(Error::UnexpectedValue);
|
||||
return Err(Error::UnexpectedValue("unexpected root"));
|
||||
}
|
||||
|
||||
let mut value = None;
|
||||
|
@ -99,7 +99,7 @@ pub enum Error {
|
|||
#[error("unexpected end of stream")]
|
||||
UnexpectedEndOfStream,
|
||||
#[error("unexpected value")]
|
||||
UnexpectedValue,
|
||||
UnexpectedValue(&'static str),
|
||||
#[error("unexpected tag")]
|
||||
UnexpectedTag,
|
||||
#[error("missing tag")]
|
||||
|
|
|
@ -39,7 +39,7 @@ fn default_namespaces() {
|
|||
from_str(
|
||||
"<NestedDe xmlns=\"WRONG\" xmlns:bar=\"BAZ\"><bar:flag>true</bar:flag></NestedDe>"
|
||||
),
|
||||
Err::<NestedDe, _>(Error::UnexpectedValue)
|
||||
Err::<NestedDe, _>(Error::UnexpectedValue("unexpected root"))
|
||||
);
|
||||
|
||||
// Correct child namespace
|
||||
|
|
|
@ -30,7 +30,7 @@ fn escape_back() {
|
|||
from_str(
|
||||
"<StructSpecialEntities xmlns=\"URI\"><string><>&"'adsad"</string><str>str&</str></StructSpecialEntities>"
|
||||
),
|
||||
Err::<StructSpecialEntities, _>(Error::UnexpectedValue)
|
||||
Err::<StructSpecialEntities, _>(Error::UnexpectedValue("string with escape characters cannot be deserialized as &str"))
|
||||
);
|
||||
|
||||
// Borrowed
|
||||
|
|
Loading…
Reference in New Issue