From 3ff858443866b5af82ee4c091d868c42f9a8a1d6 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Mon, 24 May 2021 00:25:54 +0200 Subject: [PATCH] remove some excepts --- async_utils/src/error.rs | 21 +++++++++++++++++++++ async_utils/src/lib.rs | 16 +++++++++++----- src/components/revision_files.rs | 1 - 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 async_utils/src/error.rs diff --git a/async_utils/src/error.rs b/async_utils/src/error.rs new file mode 100644 index 00000000..bd9e9020 --- /dev/null +++ b/async_utils/src/error.rs @@ -0,0 +1,21 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum Error { + #[error("`{0}`")] + Generic(String), +} + +pub type Result = std::result::Result; + +impl From> for Error { + fn from(error: crossbeam_channel::SendError) -> Self { + Self::Generic(format!("send error: {}", error)) + } +} + +impl From> for Error { + fn from(error: std::sync::PoisonError) -> Self { + Self::Generic(format!("poison error: {}", error)) + } +} diff --git a/async_utils/src/lib.rs b/async_utils/src/lib.rs index c17ff8bf..2a3edeb5 100644 --- a/async_utils/src/lib.rs +++ b/async_utils/src/lib.rs @@ -1,4 +1,7 @@ +mod error; + use crossbeam_channel::Sender; +use error::Result; use std::sync::{Arc, Mutex}; pub trait AsyncJob: Send + Sync + Clone { @@ -70,7 +73,9 @@ impl let self_arc = self.clone(); rayon_core::spawn(move || { - self_arc.run_job(task); + if let Err(e) = self_arc.run_job(task) { + log::error!("async job error: {}", e); + } }); return true; @@ -79,11 +84,10 @@ impl false } - //TODO: return Result - fn run_job(&self, mut task: J) { + fn run_job(&self, mut task: J) -> Result<()> { //limit the pending scope { - let _pending = self.pending.lock().expect(""); + let _pending = self.pending.lock()?; task.run(); @@ -91,10 +95,12 @@ impl *last = Some(task); } - self.sender.send(self.notification).expect("send failed"); + self.sender.send(self.notification)?; } self.check_for_job(); + + Ok(()) } /// diff --git a/src/components/revision_files.rs b/src/components/revision_files.rs index 8003dc5e..f0f86f01 100644 --- a/src/components/revision_files.rs +++ b/src/components/revision_files.rs @@ -42,7 +42,6 @@ pub struct RevisionFilesComponent { theme: SharedTheme, //TODO: store TreeFiles in `tree` files: Vec, - // current_file: Option<(String, Either)>, current_file: SyntaxTextComponent, tree: FileTree, scroll_top: Cell,