Cleanup HookError tracing logic.

Use `Result::or_else` instead of matching and no-oping the `Ok` case
manually and extract a helper to centralize repeated trace logic.
This commit is contained in:
John Sirois 2016-07-14 20:37:13 -06:00
parent 0c5674dd47
commit 8ef7b4e0c6

View file

@ -51,19 +51,7 @@ impl StoreIdAccessor for Aspect {
&HDA::StoreIdAccess(accessor) => accessor.access(id), &HDA::StoreIdAccess(accessor) => accessor.access(id),
_ => unreachable!(), _ => unreachable!(),
}; };
trace_hook_errors(res)
match res {
Ok(res) => Ok(res),
Err(e) => {
if !e.is_aborting() {
trace_error(&e);
// ignore error if it is not aborting, as we printed it already
Ok(())
} else {
Err(e)
}
}
}
}) })
} }
} }
@ -94,19 +82,7 @@ impl MutableHookDataAccessor for Aspect {
&HDA::NonMutableAccess(ref accessor) => accessor.access(fle), &HDA::NonMutableAccess(ref accessor) => accessor.access(fle),
_ => unreachable!(), _ => unreachable!(),
}; };
trace_hook_errors(res)
match res {
Ok(res) => Ok(res),
Err(e) => {
if !e.is_aborting() {
trace_error(&e);
// ignore error if it is not aborting, as we printed it already
Ok(())
} else {
Err(e)
}
}
}
}) })
} }
} }
@ -123,10 +99,13 @@ impl NonMutableHookDataAccessor for Aspect {
&HDA::NonMutableAccess(accessor) => accessor.access(fle), &HDA::NonMutableAccess(accessor) => accessor.access(fle),
_ => unreachable!(), _ => unreachable!(),
}; };
trace_hook_errors(res)
})
}
}
match res { fn trace_hook_errors(res: HookResult<()>) -> HookResult<()> {
Ok(res) => Ok(res), res.or_else(|e| {
Err(e) => {
if !e.is_aborting() { if !e.is_aborting() {
trace_error(&e); trace_error(&e);
// ignore error if it is not aborting, as we printed it already // ignore error if it is not aborting, as we printed it already
@ -134,9 +113,6 @@ impl NonMutableHookDataAccessor for Aspect {
} else { } else {
Err(e) Err(e)
} }
}
}
}) })
}
} }