1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Log warning instead of error when failing to decode RON in storage (#2961)

* Log warning instead of error when failing to decode RON in storage

* New web demo

* Clean up some warn/error logging

* Avoid deadlock that could happen on crash

* Log errors using console.warn, because console.error can cause crashes

* Use patched version of wasm-bindgen-cli, allowing >2GB memory

* New web demo
This commit is contained in:
Emil Ernerfeldt
2023-04-27 09:45:44 +02:00
committed by GitHub
parent f76eefb98d
commit 3d6a15f442
10 changed files with 41 additions and 29 deletions

View File

@@ -1051,7 +1051,13 @@ impl Storage for DummyStorage {
pub fn get_value<T: serde::de::DeserializeOwned>(storage: &dyn Storage, key: &str) -> Option<T> {
storage
.get_string(key)
.and_then(|value| ron::from_str(&value).ok())
.and_then(|value| match ron::from_str(&value) {
Ok(value) => Some(value),
Err(err) => {
log::warn!("Failed to decode RON: {err}");
None
}
})
}
/// Serialize the given value as [RON](https://github.com/ron-rs/ron) and store with the given key.

View File

@@ -529,7 +529,7 @@ impl AppRunnerRef {
log::debug!("Unsubscribing from {} events", events_to_unsubscribe.len());
for x in events_to_unsubscribe {
if let Err(err) = x.unsubscribe() {
log::error!("Failed to unsubscribe from event: {err:?}");
log::warn!("Failed to unsubscribe from event: {err:?}");
}
}
}
@@ -560,7 +560,7 @@ impl AppRunnerRef {
if self.has_panicked() {
None
} else {
let lock = self.runner.borrow_mut();
let lock = self.runner.try_borrow_mut().ok()?;
if lock.is_destroyed.fetch() {
None
} else {

View File

@@ -192,7 +192,7 @@ pub fn set_clipboard_text(s: &str) {
let future = wasm_bindgen_futures::JsFuture::from(promise);
let future = async move {
if let Err(err) = future.await {
log::error!("Copy/cut action denied: {:?}", err);
log::error!("Copy/cut action failed: {err:?}");
}
};
wasm_bindgen_futures::spawn_local(future);

View File

@@ -18,7 +18,7 @@ pub fn load_memory(ctx: &egui::Context) {
ctx.memory_mut(|m| *m = memory);
}
Err(err) => {
log::error!("Failed to parse memory RON: {}", err);
log::warn!("Failed to parse memory RON: {err}");
}
}
}
@@ -34,7 +34,7 @@ pub fn save_memory(ctx: &egui::Context) {
local_storage_set("egui_memory_ron", &ron);
}
Err(err) => {
log::error!("Failed to serialize memory as RON: {}", err);
log::warn!("Failed to serialize memory as RON: {err}");
}
}
}

View File

@@ -37,7 +37,11 @@ impl log::Log for WebLogger {
log::Level::Debug => console::debug(&msg),
log::Level::Info => console::info(&msg),
log::Level::Warn => console::warn(&msg),
log::Level::Error => console::error(&msg),
// Using console.error causes crashes for unknown reason
// https://github.com/emilk/egui/pull/2961
// log::Level::Error => console::error(&msg),
log::Level::Error => console::warn(&format!("ERROR: {msg}")),
}
}
@@ -66,9 +70,11 @@ mod console {
#[wasm_bindgen(js_namespace = console)]
pub fn warn(s: &str);
/// `console.error`
#[wasm_bindgen(js_namespace = console)]
pub fn error(s: &str);
// Using console.error causes crashes for unknown reason
// https://github.com/emilk/egui/pull/2961
// /// `console.error`
// #[wasm_bindgen(js_namespace = console)]
// pub fn error(s: &str);
}
}

View File

@@ -311,7 +311,7 @@ impl Painter {
height_in_pixels,
);
} else {
log::error!("Ignoring window resize notification with no surface created via Painter::set_window()");
log::warn!("Ignoring window resize notification with no surface created via Painter::set_window()");
}
}

View File

@@ -21,8 +21,8 @@ impl EguiGlow {
shader_version: Option<ShaderVersion>,
) -> Self {
let painter = crate::Painter::new(gl, "", shader_version)
.map_err(|error| {
log::error!("error occurred in initializing painter:\n{}", error);
.map_err(|err| {
log::error!("error occurred in initializing painter:\n{err}");
})
.unwrap();