fix(error): address deserialize errors include origin

feat/type-attributes
Tomáš Mládek 2023-01-04 21:16:38 +01:00
parent 89bca64d23
commit a72b871185
1 changed files with 13 additions and 5 deletions

View File

@ -52,10 +52,12 @@ impl Address {
)?)),
b'A' => Ok(Self::Attribute(String::from_utf8(digest_content)?)),
b'X' => Ok(Self::Url(String::from_utf8(digest_content)?)),
_ => Err(anyhow!("Unknown identity marker.")),
_ => Err(anyhow!("Error decoding address: Unknown identity marker.")),
}
}
_ => Err(anyhow!("Unknown hash function type.")),
_ => Err(anyhow!(
"Error decoding address: Unknown hash function type."
)),
}
}
}
@ -82,8 +84,10 @@ impl<'de> Visitor<'de> for AddressVisitor {
where
E: de::Error,
{
let bytes = b58_decode(str).map_err(de::Error::custom)?;
Address::decode(bytes.as_ref()).map_err(de::Error::custom)
let bytes = b58_decode(str)
.map_err(|e| de::Error::custom(format!("Error deserializing address: {}", e)))?;
Address::decode(bytes.as_ref())
.map_err(|e| de::Error::custom(format!("Error deserializing address: {}", e)))
}
}
@ -100,7 +104,11 @@ impl FromStr for Address {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Address::decode(b58_decode(s)?.as_ref())
Address::decode(
b58_decode(s)
.map_err(|e| anyhow!("Error deserializing address: {}", e))?
.as_ref(),
)
}
}