From ebfa153e2a302ed17892b9ce561aa7f3c641a2fe Mon Sep 17 00:00:00 2001 From: "Mayeul@Zama" <69792125+mayeul-zama@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:59:25 +0200 Subject: [PATCH] fix(wasm): return error instead of unwrap --- .../js_high_level_api/integers.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs b/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs index 8c19a4f656..6f00bb5c6d 100644 --- a/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs +++ b/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs @@ -980,8 +980,10 @@ macro_rules! define_expander_get_method { pub fn [] (&mut self, index: usize) -> Result<[], JsError> { catch_panic_result(|| { self.0.get::]>(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([]) }) } @@ -1003,8 +1005,10 @@ macro_rules! define_expander_get_method { pub fn [] (&mut self, index: usize) -> Result<[], JsError> { catch_panic_result(|| { self.0.get::]>(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([]) }) } @@ -1026,8 +1030,10 @@ impl CompactCiphertextListExpander { catch_panic_result(|| { self.0 .get::(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) }) }