remove .expect() in impl TryFrom<PgNumeric> for BigDecimal

This commit is contained in:
Austin Bonander 2020-03-18 19:12:14 -07:00
parent 979c5cc944
commit 7ffec2fef8

View File

@ -125,8 +125,9 @@ impl TryFrom<PgNumeric> for BigDecimal {
cents.push((digit % 100) as u8);
}
let bigint = BigInt::from_radix_be(sign, &cents, 100)
.expect("BUG digit outside of given radix, check math above");
let bigint = BigInt::from_radix_be(sign, &cents, 100).ok_or_else(|e| {
crate::Error::Decode("PgNumeric contained an out-of-range digit".into())
})?;
Ok(BigDecimal::new(bigint, scale))
}