diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa0911bc..b9681478b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.5.5 + +impl Error for JsError + # 0.5.4 * use owned string for DefaultAtom instantiation diff --git a/Cargo.toml b/Cargo.toml index 16c3b2554..53af77f80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hirofa_utils" -version = "0.5.4" +version = "0.5.5" authors = ["HiRoFa "] edition = "2018" description = "Utils project which is depended on by several other projects" diff --git a/src/js_utils/adapters/promises.rs b/src/js_utils/adapters/promises.rs index a1543b2eb..2ee86d4b0 100644 --- a/src/js_utils/adapters/promises.rs +++ b/src/js_utils/adapters/promises.rs @@ -52,17 +52,14 @@ where Ok(val_ref) => { prom_ref .js_promise_resolve(realm, &val_ref) - .ok() .expect("prom resolution failed"); } Err(err) => { let err_ref = realm .js_error_create(err.get_name(), err.get_message(), err.get_stack()) - .ok() .expect("could not create str"); prom_ref .js_promise_reject(realm, &err_ref) - .ok() .expect("prom rejection failed"); } } @@ -71,11 +68,9 @@ where // todo use error:new_error(err) let err_ref = realm .js_error_create(err.get_name(), err.get_message(), err.get_stack()) - .ok() .expect("could not create str"); prom_ref .js_promise_reject(realm, &err_ref) - .ok() .expect("prom rejection failed"); } } @@ -138,17 +133,14 @@ pub(crate) fn new_resolving_promise_async( Ok(val_ref) => { prom_ref .js_promise_resolve(realm, &val_ref) - .ok() .expect("prom resolution failed"); } Err(err) => { let err_ref = realm .js_error_create(err.get_name(), err.get_message(), err.get_stack()) - .ok() .expect("could not create err"); prom_ref .js_promise_reject(realm, &err_ref) - .ok() .expect("prom rejection failed"); } } @@ -157,11 +149,9 @@ pub(crate) fn new_resolving_promise_async( // todo use error:new_error(err) let err_ref = realm .js_error_create(err.get_name(), err.get_message(), err.get_stack()) - .ok() .expect("could not create str"); prom_ref .js_promise_reject(realm, &err_ref) - .ok() .expect("prom rejection failed"); } } diff --git a/src/js_utils/mod.rs b/src/js_utils/mod.rs index dba3ee418..7d5f4013b 100644 --- a/src/js_utils/mod.rs +++ b/src/js_utils/mod.rs @@ -13,6 +13,7 @@ pub trait ScriptPreProcessor { fn process(&self, script: &mut Script) -> Result<(), JsError>; } +#[derive(Debug)] pub struct JsError { name: String, message: String, @@ -48,6 +49,12 @@ impl JsError { } } +impl std::error::Error for JsError { + fn description(&self) -> &str { + self.get_message() + } +} + impl std::fmt::Display for JsError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { let e = format!("{}: {}\n{}", self.name, self.message, self.stack); @@ -55,6 +62,12 @@ impl std::fmt::Display for JsError { } } +impl From for JsError { + fn from(e: Error) -> Self { + JsError::new_string(format!("{}", e)) + } +} + pub struct Script { path: String, code: String,