diff --git a/src/util/amount.rs b/src/util/amount.rs index 54fe24d3..2a250734 100644 --- a/src/util/amount.rs +++ b/src/util/amount.rs @@ -185,7 +185,22 @@ impl fmt::Display for ParseAmountError { #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] -impl std::error::Error for ParseAmountError {} +impl std::error::Error for ParseAmountError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + use self::ParseAmountError::*; + + match *self { + Negative + | TooBig + | TooPrecise + | InvalidFormat + | InputTooLarge + | InvalidCharacter(_) + | UnknownDenomination(_) + | PossiblyConfusingDenomination(_) => None + } + } +} fn is_too_precise(s: &str, precision: usize) -> bool { s.contains('.') || precision >= s.len() || s.chars().rev().take(precision).any(|d| d != '0')