Skip to content

Commit

Permalink
[SM-1384] Fix panic on re-registering logger | WASM (#935)
Browse files Browse the repository at this point in the history
## ๐ŸŽŸ๏ธ 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
  • Loading branch information
Thomas-Avery authored Sep 12, 2024
1 parent c04b9a0 commit b00d337
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions crates/bitwarden-wasm/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::rc::Rc;
use argon2::{Algorithm, Argon2, Params, Version};
use bitwarden_json::client::Client as JsonClient;
use js_sys::Promise;
use log::Level;
use log::{set_max_level, Level};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::future_to_promise;

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

Self(Rc::new(bitwarden_json::client::Client::new(settings_input)))
Expand Down

0 comments on commit b00d337

Please sign in to comment.