diff --git a/merde/examples/return-deserialize.rs b/merde/examples/return-deserialize.rs index 170ce7c..d289f63 100644 --- a/merde/examples/return-deserialize.rs +++ b/merde/examples/return-deserialize.rs @@ -6,7 +6,7 @@ where T: OwnedValueDeserialize, { // here `s` is a `String`, but pretend we're making - // a network request intead — the point is is that we + // a network request instead — the point is is that we // need to borrow from a local from the function body. let value: Value = merde_json::from_str_via_value(&s).map_err(|e| e.to_static())?; Ok(T::owned_from_value(Some(value))?) diff --git a/merde_core/src/deserialize.rs b/merde_core/src/deserialize.rs index 65e24c2..e9145b3 100644 --- a/merde_core/src/deserialize.rs +++ b/merde_core/src/deserialize.rs @@ -318,7 +318,10 @@ where Some(Value::Map(obj)) => { let mut map = std::collections::HashMap::new(); for (key, val) in obj.iter() { - let parsed_key = K::from_str(key).map_err(|_| MerdeError::InvalidKey)?; + let parsed_key = K::from_str(key).map_err(|_| MerdeError::InvalidKey { + key: key.clone().into_static(), + type_name: std::any::type_name::(), + })?; let parsed_value = V::from_value_ref(Some(val))?; map.insert(parsed_key, parsed_value); } diff --git a/merde_core/src/error.rs b/merde_core/src/error.rs index 333f84b..609d9b4 100644 --- a/merde_core/src/error.rs +++ b/merde_core/src/error.rs @@ -71,7 +71,10 @@ pub enum MerdeError { MissingValue, /// While calling out to [`FromStr::from_str`](std::str::FromStr::from_str) to build a [`HashMap`](std::collections::HashMap), we got an error. - InvalidKey, + InvalidKey { + key: CowStr<'static>, + type_name: &'static str, + }, /// While parsing a datetime, we got an error InvalidDateTimeValue, @@ -111,8 +114,12 @@ impl std::fmt::Display for MerdeError { MerdeError::MissingValue => { write!(f, "Missing value") } - MerdeError::InvalidKey => { - write!(f, "Invalid key") + MerdeError::InvalidKey { key, type_name } => { + write!( + f, + "Invalid key: couldn't convert {:?} to type {}", + key, type_name + ) } MerdeError::InvalidDateTimeValue => { write!(f, "Invalid date/time value")