Skip to content

Commit

Permalink
fix(wasm): return error instead of unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Jun 26, 2024
1 parent 1d61376 commit ebfa153
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,10 @@ macro_rules! define_expander_get_method {
pub fn [<get_uint $num_bits>] (&mut self, index: usize) -> Result<[<FheUint $num_bits>], JsError> {
catch_panic_result(|| {
self.0.get::<crate::[<FheUint $num_bits>]>(index)
.unwrap()
.map_err(into_js_error)
.map_or_else(
|| Err(JsError::new(&format!("Index {index} is out of bounds"))),
|a| a.map_err(into_js_error),
)
.map([<FheUint $num_bits>])
})
}
Expand All @@ -1003,8 +1005,10 @@ macro_rules! define_expander_get_method {
pub fn [<get_int $num_bits>] (&mut self, index: usize) -> Result<[<FheInt $num_bits>], JsError> {
catch_panic_result(|| {
self.0.get::<crate::[<FheInt $num_bits>]>(index)
.unwrap()
.map_err(into_js_error)
.map_or_else(
|| Err(JsError::new(&format!("Index {index} is out of bounds"))),
|a| a.map_err(into_js_error),
)
.map([<FheInt $num_bits>])
})
}
Expand All @@ -1026,8 +1030,10 @@ impl CompactCiphertextListExpander {
catch_panic_result(|| {
self.0
.get::<crate::FheBool>(index)
.unwrap()
.map_err(into_js_error)
.map_or_else(
|| Err(JsError::new(&format!("Index {index} is out of bounds"))),
|a| a.map_err(into_js_error),
)
.map(FheBool)
})
}
Expand Down

0 comments on commit ebfa153

Please sign in to comment.