Skip to content

Commit b00d337

Browse files
authored
[SM-1384] Fix panic on re-registering logger | WASM (#935)
## 🎟️ Tracking <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> https://bitwarden.atlassian.net/browse/SM-1384 ## 📔 Objective <!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. --> When creating multiple WASM clients, a panic occurs `failed to initialize logger: SetLoggerError())`. Looks to be the same thing we fixed: #181 #676 ## ⏰ 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 <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+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
1 parent c04b9a0 commit b00d337

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

crates/bitwarden-wasm/src/client.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::rc::Rc;
44
use argon2::{Algorithm, Argon2, Params, Version};
55
use bitwarden_json::client::Client as JsonClient;
66
use js_sys::Promise;
7-
use log::Level;
7+
use log::{set_max_level, Level};
88
use wasm_bindgen::prelude::*;
99
use wasm_bindgen_futures::future_to_promise;
1010

@@ -37,10 +37,9 @@ impl BitwardenClient {
3737
#[wasm_bindgen(constructor)]
3838
pub fn new(settings_input: Option<String>, log_level: Option<LogLevel>) -> Self {
3939
console_error_panic_hook::set_once();
40-
if let Err(e) =
41-
console_log::init_with_level(convert_level(log_level.unwrap_or(LogLevel::Info)))
42-
{
43-
panic!("failed to initialize logger: {:?}", e);
40+
let log_level = convert_level(log_level.unwrap_or(LogLevel::Info));
41+
if let Err(_e) = console_log::init_with_level(log_level) {
42+
set_max_level(log_level.to_level_filter())
4443
}
4544

4645
Self(Rc::new(bitwarden_json::client::Client::new(settings_input)))

0 commit comments

Comments
 (0)