Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More error handling improvements #87

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/backend/luna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>())
{
(Some(&s), _) => s,
(_, Some(s)) => s,
(None, None) => "<No panic message>"
};
bail!("Worker thread panic: {msg}");
}
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading