Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM-1384] Fix panic on re-registering logger | WASM #935

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bitwarden-wasm/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use argon2::{Algorithm, Argon2, Params, Version};
use bitwarden_json::client::Client as JsonClient;
use js_sys::Promise;
use log::Level;
use log::{warn, Level};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::future_to_promise;

Expand Down Expand Up @@ -37,10 +37,10 @@
#[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) =
if let Err(_e) =

Check warning on line 40 in crates/bitwarden-wasm/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm/src/client.rs#L40

Added line #L40 was not covered by tests
console_log::init_with_level(convert_level(log_level.unwrap_or(LogLevel::Info)))
{
panic!("failed to initialize logger: {:?}", e);
warn!("Logger already initialized, log level will not be changed.");

Check warning on line 43 in crates/bitwarden-wasm/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-wasm/src/client.rs#L43

Added line #L43 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably going to be confusing to get a warning when you setup multiple sdk clients. If we do want to warn about this we should check if the log level is different.

Copy link
Contributor Author

@Thomas-Avery Thomas-Avery Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, at the time of looking at the console_log crate, I didn't think it was possible.

After further research, I found out we can use the log crate functions, and we can just set the level.

Thoughts on this approach?

https://docs.rs/log/0.4.22/log/fn.set_max_level.html

Edit here 3a86e8e

}

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