diff --git a/instant-xml-macros/src/de.rs b/instant-xml-macros/src/de.rs index a8e7cd5..17ec43d 100644 --- a/instant-xml-macros/src/de.rs +++ b/instant-xml-macros/src/de.rs @@ -127,7 +127,7 @@ fn deserialize_wrapped_enum( let node = match deserializer.next() { Some(result) => result?, - None => return Err(Error::MissingValue), + None => return Err(Error::MissingValue(&::KIND)), }; let data = match node { diff --git a/instant-xml/src/impls.rs b/instant-xml/src/impls.rs index b4fa659..20209ed 100644 --- a/instant-xml/src/impls.rs +++ b/instant-xml/src/impls.rs @@ -26,7 +26,7 @@ impl<'xml> FromXml<'xml> for bool { fn deserialize<'cx>(deserializer: &'cx mut Deserializer<'cx, 'xml>) -> Result { FromXmlStr::::deserialize(deserializer)? .0 - .ok_or(Error::MissingValue) + .ok_or(Error::MissingValue(&Kind::Scalar)) } const KIND: Kind<'static> = Kind::Scalar; @@ -72,7 +72,7 @@ macro_rules! from_xml_for_number { ) -> Result { FromXmlStr::::deserialize(deserializer)? .0 - .ok_or(Error::MissingValue) + .ok_or(Error::MissingValue(&Kind::Scalar)) } const KIND: Kind<'static> = Kind::Scalar; @@ -97,7 +97,7 @@ impl<'xml> FromXml<'xml> for char { fn deserialize<'cx>(deserializer: &'cx mut Deserializer<'cx, 'xml>) -> Result { FromXmlStr::::deserialize(deserializer)? .0 - .ok_or(Error::MissingValue) + .ok_or(Error::MissingValue(&Kind::Scalar)) } const KIND: Kind<'static> = Kind::Scalar; diff --git a/instant-xml/src/lib.rs b/instant-xml/src/lib.rs index fd1cf2a..7579389 100644 --- a/instant-xml/src/lib.rs +++ b/instant-xml/src/lib.rs @@ -39,7 +39,7 @@ pub trait FromXml<'xml>: Sized { // If the missing field is of type `Option` then treat is as `None`, // otherwise it is an error. fn missing_value() -> Result { - Err(Error::MissingValue) + Err(Error::MissingValue(&Self::KIND)) } const KIND: Kind<'static>; @@ -95,7 +95,7 @@ pub enum Error { #[error("missing tag")] MissingTag, #[error("missing value")] - MissingValue, + MissingValue(&'static Kind<'static>), #[error("unexpected token: {0}")] UnexpectedToken(String), #[error("missing prefix")] @@ -112,7 +112,7 @@ pub enum Error { DuplicateValue, } -#[derive(Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub enum Kind<'a> { Scalar, Element(Id<'a>), diff --git a/instant-xml/tests/de-direct.rs b/instant-xml/tests/de-direct.rs index b15c882..1558712 100644 --- a/instant-xml/tests/de-direct.rs +++ b/instant-xml/tests/de-direct.rs @@ -1,6 +1,6 @@ use similar_asserts::assert_eq; -use instant_xml::{from_str, Error, FromXml}; +use instant_xml::{from_str, Error, FromXml, Kind}; #[derive(Debug, Eq, PartialEq, FromXml)] #[xml(ns("URI"))] @@ -24,12 +24,12 @@ fn direct_namespaces() { from_str( "true" ), - Err::(Error::MissingValue) + Err::(Error::MissingValue(&Kind::Scalar)) ); // Wrong direct namespace - missing namespace assert_eq!( from_str("true"), - Err::(Error::MissingValue) + Err::(Error::MissingValue(&Kind::Scalar)) ); } diff --git a/instant-xml/tests/de-ns.rs b/instant-xml/tests/de-ns.rs index 2caec63..2458f0b 100644 --- a/instant-xml/tests/de-ns.rs +++ b/instant-xml/tests/de-ns.rs @@ -1,6 +1,6 @@ use similar_asserts::assert_eq; -use instant_xml::{from_str, Error, FromXml}; +use instant_xml::{from_str, Error, FromXml, Id, Kind}; #[derive(Debug, Eq, PartialEq, FromXml)] struct NestedWrongNamespace { @@ -71,7 +71,9 @@ fn default_namespaces() { // Wrong child namespace assert_eq!( from_str("true"), - Err::(Error::MissingValue) + Err::( + Error::MissingValue(&Kind::Element(Id { ns: "", name: "NestedWrongNamespace" })) + ) ); } @@ -111,7 +113,7 @@ fn other_namespaces() { from_str( "true" ), - Err::(Error::MissingValue) + Err::(Error::MissingValue(&Kind::Scalar)) ); // Other namespace not-nested - missing parser prefix @@ -119,7 +121,7 @@ fn other_namespaces() { from_str( "true" ), - Err::(Error::MissingValue) + Err::(Error::MissingValue(&Kind::Scalar)) ); // Correct child other namespace