remove some excepts

This commit is contained in:
Stephan Dilly 2021-05-24 00:25:54 +02:00
parent 9b6dd60fe0
commit 3ff8584438
3 changed files with 32 additions and 6 deletions

21
async_utils/src/error.rs Normal file
View file

@ -0,0 +1,21 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("`{0}`")]
Generic(String),
}
pub type Result<T> = std::result::Result<T, Error>;
impl<T> From<crossbeam_channel::SendError<T>> for Error {
fn from(error: crossbeam_channel::SendError<T>) -> Self {
Self::Generic(format!("send error: {}", error))
}
}
impl<T> From<std::sync::PoisonError<T>> for Error {
fn from(error: std::sync::PoisonError<T>) -> Self {
Self::Generic(format!("poison error: {}", error))
}
}

View file

@ -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<J: 'static + AsyncJob, T: Copy + Send + 'static>
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<J: 'static + AsyncJob, T: Copy + Send + 'static>
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<J: 'static + AsyncJob, T: Copy + Send + 'static>
*last = Some(task);
}
self.sender.send(self.notification).expect("send failed");
self.sender.send(self.notification)?;
}
self.check_for_job();
Ok(())
}
///

View file

@ -42,7 +42,6 @@ pub struct RevisionFilesComponent {
theme: SharedTheme,
//TODO: store TreeFiles in `tree`
files: Vec<TreeFile>,
// current_file: Option<(String, Either<ui::SyntaxText, String>)>,
current_file: SyntaxTextComponent,
tree: FileTree,
scroll_top: Cell<usize>,