From 2e1ae997dd6b9c90ca635b4fd076ebf646116ca9 Mon Sep 17 00:00:00 2001 From: Steven Enamakel Date: Mon, 11 May 2026 19:04:09 -0700 Subject: [PATCH] fix(runtime-cef): replace assert_eq! in CefRuntime::init with diagnostic panic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous `assert_eq!(cef::initialize(...), 1)` produces an opaque `assertion left == right` panic when CEF browser-process init fails, with no information about the cause. In production this hides the dominant trigger — a second app instance whose cache lock is still held by the primary — behind a useless stack trace (Sentry OPENHUMAN-TAURI-A, 442 events across Win10/11 + Linux, all releases). Replace the assert with a logged panic that includes the actual return code and `cache_path`. The expectation is that callers register `tauri-plugin-single-instance` before `Builder::build()` to remove the primary cause; this change ensures any remaining init failure produces an actionable Sentry event instead of a bare assertion. --- crates/tauri-runtime-cef/src/lib.rs | 33 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/crates/tauri-runtime-cef/src/lib.rs b/crates/tauri-runtime-cef/src/lib.rs index 1341cb18d6e0..6f964ecc8a3e 100644 --- a/crates/tauri-runtime-cef/src/lib.rs +++ b/crates/tauri-runtime-cef/src/lib.rs @@ -2068,15 +2068,32 @@ impl CefRuntime { cache_path: cache_path.to_string_lossy().to_string().as_str().into(), ..Default::default() }; - assert_eq!( - cef::initialize( - Some(args.as_main_args()), - Some(&settings), - Some(&mut app), - std::ptr::null_mut() - ), - 1 + // OpenHuman: replace the original `assert_eq!(cef::initialize(...), 1)` + // with a logged, panic-with-context fallback. The dominant trigger for + // CEF returning 0 here is a second app instance whose cache lock is + // still held by the primary (Sentry OPENHUMAN-TAURI-A). The shell now + // registers `tauri-plugin-single-instance` to prevent that race, but if + // CEF ever fails to initialize for another reason (corrupt cache, + // missing helpers, sandbox denied, …) we want the Sentry event to + // include the cache path + return code instead of a bare + // `assertion left == right` with no actionable info. + let init_ret = cef::initialize( + Some(args.as_main_args()), + Some(&settings), + Some(&mut app), + std::ptr::null_mut(), ); + if init_ret != 1 { + let cache_display = cache_path.display(); + log::error!( + "[cef-init] cef::initialize returned {init_ret} (expected 1); cache_path={cache_display}" + ); + panic!( + "cef::initialize failed (returned {init_ret}, expected 1); cache_path={cache_display}. \ + This usually means another instance of the app is already running and holds the CEF \ + cache lock — make sure tauri-plugin-single-instance is registered before Builder::build()." + ); + } // Initialize GTK for system tray support on Linux. // The muda crate (used by TrayIconBuilder) requires GTK to be initialized.