From 8b44f55c82270d70ff2db5f7ccde905395a273c1 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Mon, 14 Oct 2024 17:53:31 +0200 Subject: [PATCH] Remove usage of snippet and just return a vanilla error (#1140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit we'll have to look into proper error handling anyways, so I'm just quickfixing this until then ## 🎟ī¸ Tracking ## 📔 Objective Snippets are not properly uploaded to npmjs. Bypassing the issue by not using snippets until we figure out error handling properly ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## đŸĻŽ Reviewer guidelines - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹī¸ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠ī¸ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or â™ģī¸ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes --- 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() } }