refactor: add better log to parse struct (#621)

This commit is contained in:
Narayan Bhat
2023-02-25 18:47:47 +05:30
committed by GitHub
parent 46f77d078b
commit 275155a84d

View File

@ -157,7 +157,7 @@ pub trait BytesExt<T> {
}
impl<T> BytesExt<T> for bytes::Bytes {
fn parse_struct<'de>(&'de self, type_name: &str) -> CustomResult<T, errors::ParsingError>
fn parse_struct<'de>(&'de self, _type_name: &str) -> CustomResult<T, errors::ParsingError>
where
T: Deserialize<'de>,
{
@ -166,7 +166,10 @@ impl<T> BytesExt<T> for bytes::Bytes {
serde_json::from_slice::<T>(self.chunk())
.into_report()
.change_context(errors::ParsingError)
.attach_printable_lazy(|| format!("Unable to parse {type_name} from bytes"))
.attach_printable_lazy(|| {
let variable_type = std::any::type_name::<T>();
format!("Unable to parse {variable_type} from bytes {self:?}")
})
}
}