Skip to content

Commit 8d64a23

Browse files
committed
try to restore original code
1 parent 29ef928 commit 8d64a23

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

native/explorer/src/datatypes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl ExDecimal {
635635
base.checked_mul(10_i128.pow(self.exp as u32))
636636
.ok_or_else(|| {
637637
ExplorerError::Other(
638-
"cannot decode a valid decimal from term; check that `coef` fits into an `i128`. error: throw(<term>)".to_string()
638+
"decimal coefficient overflow: value exceeds i128 limits".to_string(),
639639
)
640640
})
641641
} else {
@@ -659,7 +659,7 @@ impl ExDecimal {
659659

660660
impl Literal for ExDecimal {
661661
fn lit(self) -> Expr {
662-
let coef = self.signed_coef().unwrap();
662+
let coef = self.signed_coef().expect("decimal coefficient overflow");
663663
let scale = self.scale();
664664

665665
Expr::Literal(LiteralValue::Scalar(Scalar::new(
@@ -727,7 +727,6 @@ impl<'a> rustler::Decoder<'a> for ExValidValue<'a> {
727727
} else if let Ok(duration) = term.decode::<ExDuration>() {
728728
Ok(ExValidValue::Duration(duration))
729729
} else if let Ok(decimal) = term.decode::<ExDecimal>() {
730-
decimal.signed_coef().map_err(|_| rustler::Error::BadArg)?;
731730
Ok(ExValidValue::Decimal(decimal))
732731
} else {
733732
Err(rustler::Error::BadArg)

native/explorer/src/series/from_list.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,17 @@ pub fn s_from_list_decimal(
240240
})
241241
}
242242

243-
TermType::Map => item
244-
.decode::<ExDecimal>()
245-
.map_err(|error| {
246-
ExplorerError::Other(format!(
247-
"cannot decode a valid decimal from term; check that `coef` fits into an `i128`. error: {error:?}"
248-
))
249-
})
250-
.and_then(|ex_decimal| {
251-
ex_decimal.signed_coef().map(|coef| AnyValue::Decimal(coef, ex_decimal.scale()))
252-
}),
243+
TermType::Map => {
244+
let ex_decimal = item
245+
.decode::<ExDecimal>()
246+
.map_err(|error| {
247+
ExplorerError::Other(format!(
248+
"cannot decode a valid decimal from term; check that `coef` fits into an `i128`. error: {error:?}"
249+
))
250+
})?;
251+
let coef = ex_decimal.signed_coef()?;
252+
Ok(AnyValue::Decimal(coef, ex_decimal.scale()))
253+
},
253254

254255
TermType::Atom => Ok(AnyValue::Null),
255256

test/explorer/series_test.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,8 +2026,7 @@ defmodule Explorer.SeriesTest do
20262026

20272027
test "overflow with values exceeding i128 limits" do
20282028
assert_raise RuntimeError,
2029-
"Generic Error: cannot decode a valid decimal from term;" <>
2030-
" check that `coef` fits into an `i128`. error: throw(<term>)",
2029+
"Generic Error: decimal coefficient overflow: value exceeds i128 limits",
20312030
fn -> Series.from_list([Decimal.new("3.4e38")]) end
20322031
end
20332032
end

0 commit comments

Comments
 (0)