From 0337574750db4437cfc024b06d73864a4147e6e6 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Mon, 13 Mar 2023 16:10:13 +0000 Subject: [PATCH] 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 X-Clacks-Overhead: GNU Terry Pratchett --- radicle/src/cob/store.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/radicle/src/cob/store.rs b/radicle/src/cob/store.rs index edaf2e23..e1ffb5ba 100644 --- a/radicle/src/cob/store.rs +++ b/radicle/src/cob/store.rs @@ -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) });