From 6eeb8f21a56409c2ec3a1f9fd89be40c319b925a Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sat, 13 Jan 2024 04:05:20 +0000 Subject: [PATCH 1/2] Display causes of errors. --- src/ui.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index a2d883fd..f87e6026 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -838,8 +838,15 @@ pub fn stop_luna() -> Result<(), Error> { pub fn display_error(result: Result<(), Error>) { #[cfg(not(feature="test-ui-replay"))] if let Err(e) = result { - let backtrace = e.backtrace(); - let message = format!("{e}\n\nBacktrace:\n\n{backtrace}"); + use std::fmt::Write; + let mut message = format!("{e}"); + for cause in e.chain().skip(1) { + write!(message, "\ncaused by: {cause} ({cause:?})").unwrap(); + } + let backtrace = format!("{}", e.backtrace()); + if backtrace != "disabled backtrace" { + write!(message, "\n\nBacktrace:\n{backtrace}").unwrap(); + } gtk::glib::idle_add_once(move || { WINDOW.with(|win_opt| { match win_opt.borrow().as_ref() { From a79eb5642ff4068505ba178a3f8fa093be11cac5 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 23 Jan 2024 09:37:22 +0000 Subject: [PATCH 2/2] Fix handling of worker thread results. --- src/backend/luna.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/luna.rs b/src/backend/luna.rs index 41062ae5..60c1db92 100644 --- a/src/backend/luna.rs +++ b/src/backend/luna.rs @@ -231,8 +231,20 @@ impl LunaStop { pub fn stop(self) -> Result<(), Error> { println!("Requesting capture stop"); self.stop_request.send(()).context("Failed sending stop request")?; - self.worker.join().err().context("Worker thread panic")?; - Ok(()) + match self.worker.join() { + Ok(result) => result, + Err(panic) => { + let msg = match ( + panic.downcast_ref::<&str>(), + panic.downcast_ref::()) + { + (Some(&s), _) => s, + (_, Some(s)) => s, + (None, None) => "" + }; + bail!("Worker thread panic: {msg}"); + } + } } }