From a183720e966489a69f9e71a7bf2f5532d96a6402 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Sat, 23 Nov 2024 16:42:01 +0100 Subject: [PATCH 1/2] fix: Log postmessage errors --- .changes/postmessage-assert-panic.md | 5 +++++ src/webview2/mod.rs | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 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 05c79b2c7..d14be6549 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -1041,10 +1041,15 @@ 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?" - ); + + #[cfg(any(debug_assertions, feature = "tracing"))] + if res.is_err() { + let error_code = windows::Win32::Foundation::GetLastError(); + #[cfg(feature = "tracing")] + tracing::error!("PostMessage failed ; is the messages queue full? Error code {error_code:?}"); + #[cfg(debug_assertions)] + eprintln!("PostMessage failed ; is the messages queue full? {error_code:?}"); + } } unsafe extern "system" fn main_thread_dispatcher_proc( From bb5acc22d781173d356b6a5fe73f495c9d4b541a Mon Sep 17 00:00:00 2001 From: FabianLars Date: Tue, 26 Nov 2024 15:56:59 +0100 Subject: [PATCH 2/2] rm getlasterror --- src/webview2/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index d14be6549..8486ad9b2 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -1040,15 +1040,19 @@ impl InnerWebView { let raw = Box::into_raw(boxed2); - let res = PostMessageW(hwnd, *EXEC_MSG_ID, WPARAM(raw as _), LPARAM(0)); + let _res = PostMessageW(hwnd, *EXEC_MSG_ID, WPARAM(raw as _), LPARAM(0)); #[cfg(any(debug_assertions, feature = "tracing"))] - if res.is_err() { - let error_code = windows::Win32::Foundation::GetLastError(); + 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!("PostMessage failed ; is the messages queue full? Error code {error_code:?}"); + tracing::error!("{}", &msg); #[cfg(debug_assertions)] - eprintln!("PostMessage failed ; is the messages queue full? {error_code:?}"); + eprintln!("{}", msg); } }