radicle: log when Ops::try_from fails

If Ops::try_from fails in from_history then it means that some
operations failed to be parsed.

If this happens, then a warning should be logged so that these failure
cases can be more easily traced.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2023-03-13 16:10:13 +00:00 committed by Alexis Sellier
parent cd12741bf2
commit 0337574750
No known key found for this signature in database
1 changed files with 12 additions and 5 deletions

View File

@ -36,13 +36,20 @@ pub trait FromHistory: Sized + Default {
/// Create an object from a history.
fn from_history(history: &History) -> Result<(Self, Lamport), Error> {
let obj = history.traverse(Self::default(), |mut acc, entry| {
if let Ok(Ops(ops)) = Ops::try_from(entry) {
if let Err(err) = acc.apply(ops) {
log::warn!("Error applying op to `{}` state: {err}", Self::type_name());
match Ops::try_from(entry) {
Ok(Ops(ops)) => {
if let Err(err) = acc.apply(ops) {
log::warn!("Error applying op to `{}` state: {err}", Self::type_name());
return ControlFlow::Break(acc);
}
}
Err(err) => {
log::warn!(
"Error decoding ops for `{}` state: {err}",
Self::type_name()
);
return ControlFlow::Break(acc);
}
} else {
return ControlFlow::Break(acc);
}
ControlFlow::Continue(acc)
});