Fix: hook registering should be hook-type agnostic

This commit is contained in:
Matthias Beyer 2016-07-15 23:36:21 +02:00
parent cb4840cce4
commit df1523db3e

View file

@ -39,7 +39,8 @@ impl<'a> Runtime<'a> {
pub fn new(cli_spec: App<'a, 'a>) -> Result<Runtime<'a>, RuntimeError> { pub fn new(cli_spec: App<'a, 'a>) -> Result<Runtime<'a>, RuntimeError> {
use std::env; use std::env;
use libimagstore::hook::position::HookPosition; use libimagstore::hook::position::HookPosition as HP;
use libimagstore::hook::Hook;
use libimagstore::error::StoreErrorKind; use libimagstore::error::StoreErrorKind;
use libimagstorestdhook::debug::DebugHook; use libimagstorestdhook::debug::DebugHook;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
@ -103,21 +104,20 @@ impl<'a> Runtime<'a> {
Store::new(storepath, store_config).map(|mut store| { Store::new(storepath, store_config).map(|mut store| {
// If we are debugging, generate hooks for all positions // If we are debugging, generate hooks for all positions
if is_debugging { if is_debugging {
let hooks = vec![ let hooks : Vec<(Box<Hook>, &str, HP)> = vec![
(DebugHook::new(HookPosition::PreCreate), HookPosition::PreCreate), (Box::new(DebugHook::new(HP::PreCreate)) , "debug", HP::PreCreate),
(DebugHook::new(HookPosition::PostCreate), HookPosition::PostCreate), (Box::new(DebugHook::new(HP::PostCreate)) , "debug", HP::PostCreate),
(DebugHook::new(HookPosition::PreRetrieve), HookPosition::PreRetrieve), (Box::new(DebugHook::new(HP::PreRetrieve)) , "debug", HP::PreRetrieve),
(DebugHook::new(HookPosition::PostRetrieve), HookPosition::PostRetrieve), (Box::new(DebugHook::new(HP::PostRetrieve)) , "debug", HP::PostRetrieve),
(DebugHook::new(HookPosition::PreUpdate), HookPosition::PreUpdate), (Box::new(DebugHook::new(HP::PreUpdate)) , "debug", HP::PreUpdate),
(DebugHook::new(HookPosition::PostUpdate), HookPosition::PostUpdate), (Box::new(DebugHook::new(HP::PostUpdate)) , "debug", HP::PostUpdate),
(DebugHook::new(HookPosition::PreDelete), HookPosition::PreDelete), (Box::new(DebugHook::new(HP::PreDelete)) , "debug", HP::PreDelete),
(DebugHook::new(HookPosition::PostDelete), HookPosition::PostDelete), (Box::new(DebugHook::new(HP::PostDelete)) , "debug", HP::PostDelete),
]; ];
// Put all debug hooks into the aspect "debug". // If hook registration fails, trace the error and warn, but continue.
// If it fails, trace the error and warn, but continue. for (hook, aspectname, position) in hooks {
for (hook, position) in hooks { if let Err(e) = store.register_hook(position, &String::from(aspectname), hook) {
if let Err(e) = store.register_hook(position, &String::from("debug"), Box::new(hook)) {
if e.err_type() == StoreErrorKind::HookRegisterError { if e.err_type() == StoreErrorKind::HookRegisterError {
trace_error_dbg(&e); trace_error_dbg(&e);
warn!("Registering debug hook with store failed"); warn!("Registering debug hook with store failed");