From e35238106e384f7899494392425f89f236c24f9c Mon Sep 17 00:00:00 2001 From: Pavel Oborin Date: Tue, 22 Oct 2024 14:00:35 +1100 Subject: [PATCH 1/4] log an error if the binding is not ready --- rust_crate/src/interface_web.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/rust_crate/src/interface_web.rs b/rust_crate/src/interface_web.rs index 22b9fd69..2e562f99 100644 --- a/rust_crate/src/interface_web.rs +++ b/rust_crate/src/interface_web.rs @@ -22,12 +22,12 @@ where #[wasm_bindgen] extern "C" { - #[wasm_bindgen(js_namespace = rinf)] - pub fn send_rust_signal_extern( + #[wasm_bindgen(js_namespace = rinf, catch)] + fn send_rust_signal_extern( resource: i32, message_bytes: Uint8Array, binary: Uint8Array, - ); + ) -> Result<(), JsValue>; // catch the JS exception } pub fn send_rust_signal_real( @@ -35,10 +35,14 @@ pub fn send_rust_signal_real( message_bytes: Vec, binary: Vec, ) -> Result<(), RinfError> { - send_rust_signal_extern( + match send_rust_signal_extern( message_id, js_sys::Uint8Array::from(message_bytes.as_slice()), js_sys::Uint8Array::from(binary.as_slice()), - ); - Ok(()) + ) { + Ok(_) => Ok(()), + Err(e) => { + Err(RinfError::NoSignalHandler) + } + } } From 6a4529824e4df4e0618346e49894d939e0e94741 Mon Sep 17 00:00:00 2001 From: Pavel Oborin Date: Tue, 22 Oct 2024 14:03:40 +1100 Subject: [PATCH 2/4] fmt --- rust_crate/src/interface_web.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rust_crate/src/interface_web.rs b/rust_crate/src/interface_web.rs index 2e562f99..367531fb 100644 --- a/rust_crate/src/interface_web.rs +++ b/rust_crate/src/interface_web.rs @@ -41,8 +41,6 @@ pub fn send_rust_signal_real( js_sys::Uint8Array::from(binary.as_slice()), ) { Ok(_) => Ok(()), - Err(e) => { - Err(RinfError::NoSignalHandler) - } + Err(e) => Err(RinfError::NoSignalHandler), } } From a390647f9125141eafac0c03f918925be9ca2924 Mon Sep 17 00:00:00 2001 From: Pavel Oborin Date: Tue, 22 Oct 2024 14:06:43 +1100 Subject: [PATCH 3/4] move pub back --- rust_crate/src/interface_web.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust_crate/src/interface_web.rs b/rust_crate/src/interface_web.rs index 367531fb..8653a2ba 100644 --- a/rust_crate/src/interface_web.rs +++ b/rust_crate/src/interface_web.rs @@ -23,7 +23,7 @@ where #[wasm_bindgen] extern "C" { #[wasm_bindgen(js_namespace = rinf, catch)] - fn send_rust_signal_extern( + pub fn send_rust_signal_extern( resource: i32, message_bytes: Uint8Array, binary: Uint8Array, From 37cbda4b9807e791512e9ec36c20c5b49c6e17c2 Mon Sep 17 00:00:00 2001 From: Pavel Oborin Date: Tue, 22 Oct 2024 14:17:05 +1100 Subject: [PATCH 4/4] print an error --- rust_crate/src/interface_web.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust_crate/src/interface_web.rs b/rust_crate/src/interface_web.rs index 8653a2ba..9e849056 100644 --- a/rust_crate/src/interface_web.rs +++ b/rust_crate/src/interface_web.rs @@ -41,6 +41,9 @@ pub fn send_rust_signal_real( js_sys::Uint8Array::from(binary.as_slice()), ) { Ok(_) => Ok(()), - Err(e) => Err(RinfError::NoSignalHandler), + Err(e) => { + crate::debug_print!("An error occured during the launch: {e:?}"); + Err(RinfError::NoSignalHandler) + } } }