From c51311ff7f0d6363501b0cc4a075b92a096b8552 Mon Sep 17 00:00:00 2001 From: Angel M De Miguel Date: Wed, 5 Jul 2023 13:55:46 +0200 Subject: [PATCH] improve: use a struct variant to clarify the error argument --- kits/javascript/src/bindings.rs | 16 ++++++++++++---- kits/javascript/src/error.rs | 2 +- kits/javascript/src/main.rs | 4 ++-- .../wasm-workers-quick-js-engine.wasm | Bin 3903414 -> 3903412 bytes 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kits/javascript/src/bindings.rs b/kits/javascript/src/bindings.rs index c9a73831..3d777bb5 100644 --- a/kits/javascript/src/bindings.rs +++ b/kits/javascript/src/bindings.rs @@ -107,9 +107,13 @@ pub fn load_bindings_into_global( } } }) - .map_err(|_| RuntimeError::InvalidBinding("send_http_request".to_string()))?, + .map_err(|_| RuntimeError::InvalidBinding { + invalid_export: "send_http_request".to_string(), + })?, ) - .map_err(|_| RuntimeError::InvalidBinding("send_http_request".to_string()))?; + .map_err(|_| RuntimeError::InvalidBinding { + invalid_export: "send_http_request".to_string(), + })?; global .set_property( @@ -122,9 +126,13 @@ pub fn load_bindings_into_global( Ok(JSValue::Null) }) - .map_err(|_| RuntimeError::InvalidBinding("console_log".to_string()))?, + .map_err(|_| RuntimeError::InvalidBinding { + invalid_export: "console_log".to_string(), + })?, ) - .map_err(|_| RuntimeError::InvalidBinding("console_log".to_string()))?; + .map_err(|_| RuntimeError::InvalidBinding { + invalid_export: "console_log".to_string(), + })?; Ok(()) } diff --git a/kits/javascript/src/error.rs b/kits/javascript/src/error.rs index 528037c1..8d234785 100644 --- a/kits/javascript/src/error.rs +++ b/kits/javascript/src/error.rs @@ -3,5 +3,5 @@ /// List of runtime errors pub enum RuntimeError { - InvalidBinding(String), + InvalidBinding { invalid_export: String }, } diff --git a/kits/javascript/src/main.rs b/kits/javascript/src/main.rs index 65579bee..d74c2d4d 100644 --- a/kits/javascript/src/main.rs +++ b/kits/javascript/src/main.rs @@ -43,8 +43,8 @@ fn main() { Ok(_) => {} Err(e) => match e { // In the future we may have more errors. - error::RuntimeError::InvalidBinding(name) => { - eprintln!("There was an error adding the '{name}' binding"); + error::RuntimeError::InvalidBinding { invalid_export } => { + eprintln!("There was an error adding the '{invalid_export}' binding"); } }, } diff --git a/kits/javascript/wasm-workers-quick-js-engine.wasm b/kits/javascript/wasm-workers-quick-js-engine.wasm index 367f112d68f3807d146526e28de08aac49ed9469..26f1597054fa62604822770b554258b61a6a80dc 100755 GIT binary patch delta 428 zcmZw7J5Rz;90l-JDBuHVMSLJH0pC*ky0pD~01^`iMxz)(VN()U7ENx#>UIYQ7mbN= zL_3oBG5iq5gbt1#ofsT``JZ$0f4lz_hj7hAHpK!g$RrkGVHRQ2Y=+IUxncBVtfT}% z$iYik{<~@38%Lk?-zh&aXOW8&J%e1B=>0+6k3tOMAcF$)kbnh9!XhleGOR!fRv`@; z$U+YCum%MvLJ8Jk12$m`wqXZ$VGqinLIpI?!2lC1AW#Jx9Ix)Xfm-}yBn2;97aj3= zBz?yOe%GW0uV0~RM7-js`}C0CnlzMjtF}oTQ?rO}5MsGDF|r4|@mS9AuLm{9j~x0c n_PFBGvYox#|%z+9qn1=<3Ljo2d2}_WIG-MzP zImm+s1z3h6l%NbNunKFi4jZruTd)lksDchPAW#PbOlW`wHaLE3M1#%f*Lyg0;hvvL zJ%3+k2NCI7=${o$-0m<{9