From b288e938f9cc256acdd76aaab78fe04b08451c93 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Sep 2016 14:52:00 +0200 Subject: [PATCH 1/3] Minify error handling in Store::update() --- libimagstore/src/store.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 5922b35f..bdda753e 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -493,10 +493,7 @@ impl Store { /// Return the `FileLockEntry` and write to disk pub fn update<'a>(&'a self, mut entry: FileLockEntry<'a>) -> Result<()> { - if let Err(e) = self._update(&mut entry) { - return Err(e).map_err_into(SEK::UpdateCallError); - } - Ok(()) + self._update(&mut entry).map_err_into(SEK::UpdateCallError) } /// Internal method to write to the filesystem store. From 07ff755ed79fe8193fde52390406ec00c0577526 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Sep 2016 14:52:55 +0200 Subject: [PATCH 2/3] Minify error handling in Store::_update with try!() --- libimagstore/src/store.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index bdda753e..f2d0af99 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -502,12 +502,11 @@ impl Store { /// This method assumes that entry is dropped _right after_ the call, hence /// it is not public. fn _update<'a>(&'a self, entry: &mut FileLockEntry<'a>) -> Result<()> { - if let Err(e) = self.execute_hooks_for_mut_file(self.pre_update_aspects.clone(), entry) { - return Err(e) - .map_err_into(SEK::PreHookExecuteError) - .map_err_into(SEK::HookExecutionError) - .map_err_into(SEK::UpdateCallError); - } + let _ = try!(self.execute_hooks_for_mut_file(self.pre_update_aspects.clone(), entry) + .map_err_into(SEK::PreHookExecuteError) + .map_err_into(SEK::HookExecutionError) + .map_err_into(SEK::UpdateCallError) + ); let mut hsmap = match self.entries.write() { Err(_) => return Err(SE::new(SEK::LockPoisoned, None)), From 15dcb26fd226736988e2f959dae71ab7530529c7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Sep 2016 14:54:38 +0200 Subject: [PATCH 3/3] Minify Runtime::new() by refactoring error tracing --- libimagstorestdhook/src/vcs/git/runtime.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/runtime.rs b/libimagstorestdhook/src/vcs/git/runtime.rs index 3daf8bf8..b35a453f 100644 --- a/libimagstorestdhook/src/vcs/git/runtime.rs +++ b/libimagstorestdhook/src/vcs/git/runtime.rs @@ -4,7 +4,7 @@ use git2::{Index, Repository}; use toml::Value; use libimagerror::into::IntoError; -use libimagerror::trace::trace_error; +use libimagerror::trace::{MapErrTrace, trace_error}; use libimagstore::hook::error::CustomData; use libimagstore::hook::error::HookErrorKind as HEK; use libimagstore::hook::result::HookResult; @@ -31,14 +31,7 @@ impl Runtime { /// returns a `Runtime` object that does _not_ contain a `Repository`. pub fn new(storepath: &PathBuf) -> Runtime { Runtime { - repository: match Repository::open(storepath) { - Ok(r) => Some(r), - Err(e) => { - trace_error(&e); - None - }, - }, - + repository: Repository::open(storepath).map_err_trace().ok(), config: None, } }