1
0
mirror of https://github.com/bobwen-dev/hunter synced 2025-04-12 00:55:41 +02:00

remove backtraces from HError

This commit is contained in:
rabite 2020-01-25 00:50:28 +01:00
parent b18e86f28e
commit 682a284afa
3 changed files with 22 additions and 36 deletions

View File

@ -14,22 +14,12 @@ use crate::mediaview::MediaError;
pub type HResult<T> = Result<T, HError>;
pub type Backtrace = Arc<failure::Backtrace>;
pub trait ArcBacktrace {
fn new_arced() -> Backtrace;
}
impl ArcBacktrace for Backtrace {
fn new_arced() -> Backtrace {
Arc::new(failure::Backtrace::new())
}
}
#[derive(Fail, Debug, Clone)]
pub enum HError {
#[fail(display = "IO error: {} ", _0)]
IoError(String, Backtrace),
IoError(String),
#[fail(display = "Mutex failed")]
MutexError,
#[fail(display = "Can't lock!")]
@ -47,11 +37,11 @@ pub enum HError {
#[fail(display = "Accessed stale value")]
StaleError,
#[fail(display = "Failed: {}", _0)]
Error(String, Backtrace),
Error(String),
#[fail(display = "Was None!")]
NoneError(Backtrace),
NoneError,
#[fail(display = "Async Error: {}", _0)]
AError(async_value::AError, Backtrace),
AError(async_value::AError),
#[fail(display = "No widget found")]
NoWidgetError,
#[fail(display = "Path: {:?} not in this directory: {:?}", path, dir)]
@ -75,7 +65,7 @@ pub enum HError {
#[fail(display = "Strip Prefix Error: {}", error)]
StripPrefixError{#[cause] error: std::path::StripPrefixError},
#[fail(display = "INofify failed: {}", _0)]
INotifyError(String, Backtrace),
INotifyError(String),
#[fail(display = "Tags not loaded yet")]
TagsNotLoadedYetError,
#[fail(display = "Input cancelled!")]
@ -276,17 +266,14 @@ where E: Into<HError> + Clone {
impl From<std::io::Error> for HError {
fn from(error: std::io::Error) -> Self {
let err = HError::IoError(format!("{}", error),
Backtrace::new_arced());
let err = HError::IoError(format!("{}", error));
err
}
}
impl From<failure::Error> for HError {
fn from(error: failure::Error) -> Self {
let err = HError::Error(format!("{}", error),
Backtrace::new_arced()
);
let err = HError::Error(format!("{}", error));
err
}
}
@ -328,7 +315,7 @@ impl<T> From<std::sync::TryLockError<T>> for HError {
impl From<std::option::NoneError> for HError {
fn from(_error: std::option::NoneError) -> Self {
let err = HError::NoneError(Backtrace::new_arced());
let err = HError::NoneError;
err
}
}
@ -342,16 +329,14 @@ impl From<std::path::StripPrefixError> for HError {
impl From<notify::Error> for HError {
fn from(error: notify::Error) -> Self {
let err = HError::INotifyError(format!("{}", error),
Backtrace::new_arced());
let err = HError::INotifyError(format!("{}", error));
err
}
}
impl From<async_value::AError> for HError {
fn from(error: async_value::AError) -> Self {
let err = HError::AError(error,
Backtrace::new_arced());
let err = HError::AError(error);
err
}
}

View File

@ -10,7 +10,7 @@ use std::path::PathBuf;
use crate::files::{Files, File, SortBy};
use crate::widget::Events;
use crate::fail::{HResult, HError, ErrorLog, Backtrace, ArcBacktrace};
use crate::fail::{HResult, HError, ErrorLog};
pub type CachedFiles = (Option<File>, Async<Files>);
@ -263,7 +263,7 @@ impl FsCache {
let mut files = file_cache.read()
.map_err(|e| HError::from(e))?
.get(&dir)
.ok_or(HError::NoneError(Backtrace::new_arced()))?
.ok_or(HError::NoneError)?
.clone();
let tab_settings = &tab_settings;
@ -406,11 +406,9 @@ impl TryFrom<DebouncedEvent> for FsEvent {
File::new_from_path(&new_path, None)?),
DebouncedEvent::Error(err, path)
=> Err(HError::INotifyError(format!("{}, {:?}", err, path),
Backtrace::new_arced()))?,
=> Err(HError::INotifyError(format!("{}, {:?}", err, path)))?,
DebouncedEvent::Rescan
=> Err(HError::INotifyError("Need to rescan".to_string(),
Backtrace::new_arced()))?,
=> Err(HError::INotifyError("Need to rescan".to_string()))?,
// Ignore NoticeRemove/NoticeWrite
_ => None?,
};
@ -499,11 +497,9 @@ impl PathFromEvent for DebouncedEvent {
DebouncedEvent::NoticeRemove(path) => Ok(path),
DebouncedEvent::Rename(old_path, _) => Ok(old_path),
DebouncedEvent::Error(err, path)
=> Err(HError::INotifyError(format!("{}, {:?}", err, path),
Backtrace::new_arced())),
=> Err(HError::INotifyError(format!("{}, {:?}", err, path))),
DebouncedEvent::Rescan
=> Err(HError::INotifyError("Need to rescan".to_string(),
Backtrace::new_arced()))
=> Err(HError::INotifyError("Need to rescan".to_string()))
}
}

View File

@ -98,11 +98,16 @@ impl Listable for ListView<Files> {
fn on_new(&mut self) -> HResult<()> {
let show_hidden = self.core.config().show_hidden();
self.content.show_hidden = show_hidden;
let file = self.content
let mut file = self.content
.iter_files()
.nth(0)
.cloned()
.unwrap_or_default();
if !file.meta.value.is_ok() {
file.meta_sync().log();
}
self.current_item = Some(file);
Ok(())
}