From b4ba5b47f235df503085150671ff16189d3d9ea9 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Tue, 31 Dec 2024 14:17:07 +0100 Subject: [PATCH] fix: log postmessage errors (#1426) --- .changes/postmessage-assert-panic.md | 5 +++++ src/webview2/mod.rs | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 .changes/postmessage-assert-panic.md diff --git a/.changes/postmessage-assert-panic.md b/.changes/postmessage-assert-panic.md new file mode 100644 index 000000000..81f9d146f --- /dev/null +++ b/.changes/postmessage-assert-panic.md @@ -0,0 +1,5 @@ +--- +"wry": "patch" +--- + +On Windows, Wry will now log PostMessage errors instead of panicking. diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index bb2bfd540..ca4bb96c7 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -1040,11 +1040,20 @@ impl InnerWebView { let raw = Box::into_raw(boxed2); - let res = PostMessageW(hwnd, *EXEC_MSG_ID, WPARAM(raw as _), LPARAM(0)); - assert!( - res.is_ok(), - "PostMessage failed ; is the messages queue full?" - ); + let _res = PostMessageW(hwnd, *EXEC_MSG_ID, WPARAM(raw as _), LPARAM(0)); + + #[cfg(any(debug_assertions, feature = "tracing"))] + if let Err(err) = _res { + let msg = format!( + "PostMessage failed ; is the messages queue full? Error code {} - {}", + err.code(), + err.message() + ); + #[cfg(feature = "tracing")] + tracing::error!("{}", &msg); + #[cfg(debug_assertions)] + eprintln!("{}", msg); + } } unsafe extern "system" fn main_thread_dispatcher_proc(