Skip to content

Commit

Permalink
add back backtraces to commonly logged errors and fix their cause
Browse files Browse the repository at this point in the history
  • Loading branch information
rabite0 committed May 11, 2019
1 parent 99980ac commit 9b463b3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 53 deletions.
66 changes: 27 additions & 39 deletions src/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ use async_value::AError;
use termion::event::Key;

use std::path::PathBuf;
use std::sync::Mutex;
use std::sync::{Arc, Mutex};

use crate::foldview::LogEntry;

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),
IoError(String, Backtrace),
#[fail(display = "Mutex failed")]
MutexError,
#[fail(display = "Can't lock!")]
Expand All @@ -34,23 +46,11 @@ pub enum HError {
#[fail(display = "Accessed stale value")]
StaleError,
#[fail(display = "Failed: {}", _0)]
Error(String),
Error(String, Backtrace),
#[fail(display = "Was None!")]
NoneError,
#[fail(display = "Not ready yet!")]
WillBeNotReady,
#[fail(display = "Not ready yet!")]
AsyncNotReadyError,
#[fail(display = "Async is stale!")]
AsyncStaleError,
#[fail(display = "Value has already been taken!")]
AsyncAlreadyTakenError,
#[fail(display = "Async has already been started!")]
AsyncAlreadyStartedError,
NoneError(Backtrace),
#[fail(display = "Async Error: {}", _0)]
AsyncError(String),
#[fail(display = "Async Error: {}", _0)]
AError(async_value::AError),
AError(async_value::AError, Backtrace),
#[fail(display = "No widget found")]
NoWidgetError,
#[fail(display = "Path: {:?} not in this directory: {:?}", path, dir)]
Expand All @@ -74,7 +74,7 @@ pub enum HError {
#[fail(display = "Strip Prefix Error: {}", error)]
StripPrefixError{#[cause] error: std::path::StripPrefixError},
#[fail(display = "INofify failed: {}", _0)]
INotifyError(String),
INotifyError(String, Backtrace),
#[fail(display = "Tags not loaded yet")]
TagsNotLoadedYetError,
#[fail(display = "Input cancelled!")]
Expand Down Expand Up @@ -159,22 +159,6 @@ impl HError {
Err(HError::ConfigLineError(line))
}

pub fn async_not_ready<T>() -> HResult<T> {
Err(HError::AsyncNotReadyError)
}

pub fn async_taken<T>() -> HResult<T> {
Err(HError::AsyncAlreadyTakenError)
}

pub fn async_error<T>(error: &HError) -> HResult<T> {
Err(HError::AsyncError(format!("{}", error)))
}

pub fn async_started<T>() -> HResult<T> {
Err(HError::AsyncAlreadyStartedError)
}

pub fn metadata_processed<T>() -> HResult<T> {
Err(HError::MetadataProcessedError)
}
Expand Down Expand Up @@ -246,14 +230,16 @@ impl<T> ErrorLog for Result<T, AError> {

impl From<std::io::Error> for HError {
fn from(error: std::io::Error) -> Self {
let err = HError::IoError(format!("{}", error));
let err = HError::IoError(format!("{}", error),
Backtrace::new_arced());
err
}
}

impl From<failure::Error> for HError {
fn from(error: failure::Error) -> Self {
let err = HError::Error(format!("{}", error));
let err = HError::Error(format!("{}", error),
Backtrace::new_arced());
err
}
}
Expand Down Expand Up @@ -295,7 +281,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;
let err = HError::NoneError(Backtrace::new_arced());
err
}
}
Expand All @@ -309,14 +295,16 @@ 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));
let err = HError::INotifyError(format!("{}", error),
Backtrace::new_arced());
err
}
}

impl From<async_value::AError> for HError {
fn from(error: async_value::AError) -> Self {
let err = HError::AError(error);
let err = HError::AError(error,
Backtrace::new_arced());
err
}
}
10 changes: 6 additions & 4 deletions src/file_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,12 @@ impl FileBrowser {
}

pub fn cache_files(&mut self) -> HResult<()> {
let files = self.get_files()?;
let selected_file = self.selected_file().ok();
self.fs_cache.put_files(files, selected_file).log();
self.main_widget_mut()?.content.meta_updated = false;
if self.main_widget().is_ok() {
let files = self.get_files()?;
let selected_file = self.selected_file().ok();
self.fs_cache.put_files(files, selected_file).log();
self.main_widget_mut()?.content.meta_updated = false;
}


// if self.cwd.parent().is_some() {
Expand Down
16 changes: 9 additions & 7 deletions src/fscache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::PathBuf;

use crate::files::{Files, File, SortBy};
use crate::widget::Events;
use crate::fail::{HResult, HError, ErrorLog};
use crate::fail::{HResult, HError, ErrorLog, Backtrace, ArcBacktrace};


#[derive(Debug, Clone)]
Expand Down Expand Up @@ -113,12 +113,12 @@ impl FsCache {
if self.files.read()?.contains_key(dir) {
self.get_cached_files(dir)
} else {
self.add_watch(&dir).log();
let dir = dir.clone();
let selection = self.get_selection(&dir).ok();
let cache = self.clone();
let files = Async::new(move |_| {
let mut files = Files::new_from_path_cancellable(&dir.path, stale)?;
cache.add_watch(&dir).log();
FsCache::apply_settingss(&cache, &mut files).ok();
Ok(files)
});
Expand All @@ -127,11 +127,11 @@ impl FsCache {
}

pub fn get_files_sync(&self, dir: &File) -> HResult<Files> {
self.add_watch(&dir).log();
let files = self.get_files(&dir, Stale::new())?.1;
let mut files = files.run_sync()?;
FsCache::apply_settingss(&self, &mut files).ok();
let files = FsCache::ensure_not_empty(files)?;
self.add_watch(&dir).log();
Ok(files)
}

Expand Down Expand Up @@ -188,8 +188,8 @@ impl FsCache {

fn add_watch(&self, dir: &File) -> HResult<()> {
if !self.watched_dirs.read()?.contains(&dir) {
self.watcher.write()?.watch(&dir.path, RecursiveMode::NonRecursive)?;
self.watched_dirs.write()?.insert(dir.clone());
self.watcher.write()?.watch(&dir.path, RecursiveMode::NonRecursive)?
}
Ok(())
}
Expand All @@ -215,7 +215,7 @@ impl FsCache {
let mut files = file_cache.read()
.map_err(|e| HError::from(e))?
.get(&dir)
.ok_or(HError::NoneError)?
.ok_or(HError::NoneError(Backtrace::new_arced()))?
.clone();
let tab_settings = &tab_settings;

Expand Down Expand Up @@ -373,9 +373,11 @@ 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))),
=> Err(HError::INotifyError(format!("{}, {:?}", err, path),
Backtrace::new_arced())),
DebouncedEvent::Rescan
=> Err(HError::INotifyError("Need to rescan".to_string()))
=> Err(HError::INotifyError("Need to rescan".to_string(),
Backtrace::new_arced()))

}
}
Expand Down
8 changes: 5 additions & 3 deletions src/proclist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,11 @@ impl Widget for ProcView {
fn refresh(&mut self) -> HResult<()> {
self.hbox.refresh().log();

self.show_output().log();
self.get_listview_mut().refresh().log();
self.get_textview().refresh().log();
if self.get_listview().len() > 0 {
self.show_output().log();
self.get_listview_mut().refresh().log();
self.get_textview().refresh().log();
}

Ok(())
}
Expand Down

0 comments on commit 9b463b3

Please sign in to comment.