Add some more error types to be more specific about what happened

This commit is contained in:
Matthias Beyer 2016-03-25 13:29:04 +01:00
parent 9f8a648600
commit 22052ba9f0
2 changed files with 8 additions and 2 deletions

View file

@ -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",

View file

@ -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> {