From c3016bef123f0b3fefc9a5999d547b5dd723930b Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 14 Oct 2024 16:52:39 +0200 Subject: [PATCH] fix: remove usage of snipper and just return a vanilla error we'll have to look into proper error handling anyways, so I'm just quickfixing this until then --- crates/bitwarden-wasm-internal/src/client.rs | 4 ++++ crates/bitwarden-wasm-internal/src/error.js | 13 ------------- crates/bitwarden-wasm-internal/src/error.rs | 11 ++++++----- 3 files changed, 10 insertions(+), 18 deletions(-) delete mode 100644 crates/bitwarden-wasm-internal/src/error.js diff --git a/crates/bitwarden-wasm-internal/src/client.rs b/crates/bitwarden-wasm-internal/src/client.rs index ac7779b2f..0a5ce27d5 100644 --- a/crates/bitwarden-wasm-internal/src/client.rs +++ b/crates/bitwarden-wasm-internal/src/client.rs @@ -49,6 +49,10 @@ impl BitwardenClient { msg } + pub fn throw(&self, msg: String) -> Result<(), crate::error::GenericError> { + Err(crate::error::GenericError(msg)) + } + /// Test method, calls http endpoint pub async fn http_get(&self, url: String) -> Result { let client = self.0.internal.get_http_client(); diff --git a/crates/bitwarden-wasm-internal/src/error.js b/crates/bitwarden-wasm-internal/src/error.js deleted file mode 100644 index cd3d3a346..000000000 --- a/crates/bitwarden-wasm-internal/src/error.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Error thrown by the WASM module. - * @param {string} message - Error message. - * @extends Error - */ -class WasmError extends Error { - constructor(message) { - super(message); - this.name = "WasmError"; - } -} - -exports.WasmError = WasmError; diff --git a/crates/bitwarden-wasm-internal/src/error.rs b/crates/bitwarden-wasm-internal/src/error.rs index 2750d2629..237ee4941 100644 --- a/crates/bitwarden-wasm-internal/src/error.rs +++ b/crates/bitwarden-wasm-internal/src/error.rs @@ -2,12 +2,13 @@ use wasm_bindgen::prelude::*; // Importing an error class defined in JavaScript instead of defining it in Rust // allows us to extend the `Error` class. It also provides much better console output. -#[wasm_bindgen(module = "/src/error.js")] +#[wasm_bindgen] extern "C" { - type WasmError; + #[wasm_bindgen(js_name = Error)] + type JsError; - #[wasm_bindgen(constructor)] - fn new(message: String) -> WasmError; + #[wasm_bindgen(constructor, js_class = Error)] + fn new(message: String) -> JsError; } pub type Result = std::result::Result; @@ -22,6 +23,6 @@ impl From for GenericError { impl From for JsValue { fn from(error: GenericError) -> Self { - WasmError::new(error.0).into() + JsError::new(error.0).into() } }