From 22052ba9f071f37290336ae0d515299095b71dc1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 25 Mar 2016 13:29:04 +0100 Subject: [PATCH] Add some more error types to be more specific about what happened --- libimagstore/src/error.rs | 4 ++++ libimagstore/src/store.rs | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index 4ad9c5f2..4fea66f0 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -20,6 +20,7 @@ pub enum StoreErrorKind { IoError, StorePathExists, StorePathCreate, + LockError, LockPoisoned, EntryAlreadyBorrowed, EntryAlreadyExists, @@ -29,6 +30,7 @@ pub enum StoreErrorKind { HeaderKeyNotFound, HeaderTypeFailure, HookRegisterError, + AspectNameNotFoundError, HookExecutionError, PreHookExecuteError, PostHookExecuteError, @@ -50,6 +52,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str { &StoreErrorKind::IoError => "File Error", &StoreErrorKind::StorePathExists => "Store path exists", &StoreErrorKind::StorePathCreate => "Store path create", + &StoreErrorKind::LockError => "Error locking datastructure", &StoreErrorKind::LockPoisoned => "The internal Store Lock has been poisoned", &StoreErrorKind::EntryAlreadyBorrowed => "Entry is already borrowed", @@ -60,6 +63,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str { &StoreErrorKind::HeaderKeyNotFound => "Header Key not found", &StoreErrorKind::HeaderTypeFailure => "Header type is wrong", &StoreErrorKind::HookRegisterError => "Hook register error", + &StoreErrorKind::AspectNameNotFoundError => "Aspect name not found", &StoreErrorKind::HookExecutionError => "Hook execution error", &StoreErrorKind::PreHookExecuteError => "Pre-Hook execution error", &StoreErrorKind::PostHookExecuteError => "Post-Hook execution error", diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index af10869e..ab895a5b 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -436,7 +436,7 @@ impl Store { let guard = guard .deref() .lock() - .map_err(|_| StoreError::new(StoreErrorKind::HookRegisterError, None)); + .map_err(|_| StoreError::new(StoreErrorKind::LockError, None)); if guard.is_err() { return Err(StoreError::new(StoreErrorKind::HookRegisterError, @@ -450,7 +450,9 @@ impl Store { return Ok(()); } } - return Err(StoreError::new(StoreErrorKind::HookRegisterError, None)); + + let annfe = StoreError::new(StoreErrorKind::AspectNameNotFoundError, None); + return Err(StoreError::new(StoreErrorKind::HookRegisterError, Some(Box::new(annfe)))); } fn get_config_for_hook(&self, name: &str) -> Option<&Value> {