From 9355629136e155d43a7eb1a485d3376778193998 Mon Sep 17 00:00:00 2001 From: daladim Date: Wed, 24 Mar 2021 09:15:55 +0100 Subject: [PATCH] add_item now returns a Result --- src/calendar/cached_calendar.rs | 3 ++- src/calendar/remote_calendar.rs | 4 ++-- src/provider.rs | 20 ++++++++++++++++---- src/traits.rs | 2 +- tests/sync.rs | 30 +++++++++++++++--------------- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/calendar/cached_calendar.rs b/src/calendar/cached_calendar.rs index a7a08a5..68e5264 100644 --- a/src/calendar/cached_calendar.rs +++ b/src/calendar/cached_calendar.rs @@ -72,8 +72,9 @@ impl PartialCalendar for CachedCalendar { self.supported_components } - async fn add_item(&mut self, item: Item) { + async fn add_item(&mut self, item: Item) -> Result<(), Box> { self.items.insert(item.id().clone(), item); + Ok(()) } async fn delete_item(&mut self, item_id: &ItemId) -> Result<(), Box> { diff --git a/src/calendar/remote_calendar.rs b/src/calendar/remote_calendar.rs index 7618943..b6ca2d1 100644 --- a/src/calendar/remote_calendar.rs +++ b/src/calendar/remote_calendar.rs @@ -92,8 +92,8 @@ impl PartialCalendar for RemoteCalendar { /// Add an item into this calendar - async fn add_item(&mut self, _item: Item) { - log::error!("Not implemented"); + async fn add_item(&mut self, _item: Item) -> Result<(), Box> { + Err("Not implemented".into()) } /// Remove an item from this calendar diff --git a/src/provider.rs b/src/provider.rs index 3b99f67..73c05d1 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -166,7 +166,11 @@ where log::error!("Inconsistency: new item {} has vanished from the remote end", id_add); continue; }, - Some(new_item) => cal_local.add_item(new_item.clone()).await, + Some(new_item) => { + if let Err(err) = cal_local.add_item(new_item.clone()).await { + log::error!("Not able to add item {} to local calendar: {}", id_add, err); + } + }, } } @@ -180,7 +184,9 @@ where if let Err(err) = cal_local.delete_item(&id_change).await { log::error!("Unable to delete item {} from local calendar: {}", id_change, err); } - cal_local.add_item(item.clone()); + if let Err(err) = cal_local.add_item(item.clone()).await { + log::error!("Unable to add item {} to local calendar: {}", id_change, err); + } }, } } @@ -192,7 +198,11 @@ where log::error!("Inconsistency: created item {} has been marked for upload but is locally missing", id_add); continue; }, - Some(item) => cal_remote.add_item(item.clone()), + Some(item) => { + if let Err(err) = cal_remote.add_item(item.clone()).await { + log::error!("Unable to add item {} to remote calendar: {}", id_add, err); + } + } }; } @@ -206,7 +216,9 @@ where if let Err(err) = cal_remote.delete_item(&id_change).await { log::error!("Unable to delete item {} from remote calendar: {}", id_change, err); } - cal_remote.add_item(item.clone()); + if let Err(err) = cal_remote.add_item(item.clone()).await { + log::error!("Unable to add item {} to remote calendar: {}", id_change, err); + } } }; } diff --git a/src/traits.rs b/src/traits.rs index e3135b7..567566d 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -42,7 +42,7 @@ pub trait PartialCalendar { async fn get_item_by_id<'a>(&'a self, id: &ItemId) -> Option<&'a Item>; /// Add an item into this calendar - async fn add_item(&mut self, item: Item); + async fn add_item(&mut self, item: Item) -> Result<(), Box>; /// Remove an item from this calendar async fn delete_item(&mut self, item_id: &ItemId) -> Result<(), Box>; diff --git a/tests/sync.rs b/tests/sync.rs index db88e69..7319ab8 100644 --- a/tests/sync.rs +++ b/tests/sync.rs @@ -84,19 +84,19 @@ async fn populate_test_provider() -> Provider Provider Provider