diff --git a/src/cache.rs b/src/cache.rs index fc2ef4a..966462a 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -143,8 +143,8 @@ impl Cache { None => return Err("should not happen, we've just tested keys are the same".into()), }; - let items_l = cal_l.get_items().await; - let items_r = cal_r.get_items().await; + let items_l = cal_l.get_items().await?; + let items_r = cal_r.get_items().await?; if keys_are_the_same(&items_l, &items_r) == false { log::debug!("Different keys for items"); diff --git a/src/calendar/cached_calendar.rs b/src/calendar/cached_calendar.rs index 3a7fd54..22d9e63 100644 --- a/src/calendar/cached_calendar.rs +++ b/src/calendar/cached_calendar.rs @@ -34,11 +34,11 @@ impl CachedCalendar { } /// Returns the list of tasks that this calendar contains - pub async fn get_tasks(&self) -> HashMap { + pub async fn get_tasks(&self) -> Result, Box> { self.get_tasks_modified_since(None).await } /// Returns the tasks that have been last-modified after `since` - pub async fn get_tasks_modified_since(&self, since: Option>) -> HashMap { + pub async fn get_tasks_modified_since(&self, since: Option>) -> Result, Box> { self.get_items_modified_since(since, Some(SearchFilter::Tasks)).await } } @@ -69,7 +69,7 @@ impl PartialCalendar for CachedCalendar { Ok(()) } - async fn get_items_modified_since(&self, since: Option>, filter: Option) -> HashMap { + async fn get_items_modified_since(&self, since: Option>, filter: Option) -> Result, Box> { let filter = filter.unwrap_or_default(); let mut map = HashMap::new(); @@ -94,7 +94,7 @@ impl PartialCalendar for CachedCalendar { map.insert(item.id().clone(), item); } - map + Ok(map) } async fn get_item_ids(&mut self) -> HashSet { @@ -109,14 +109,14 @@ impl PartialCalendar for CachedCalendar { #[async_trait] impl CompleteCalendar for CachedCalendar { /// Returns the items that have been deleted after `since` - async fn get_items_deleted_since(&self, since: DateTime) -> HashSet { - self.deleted_items.range(since..) + async fn get_items_deleted_since(&self, since: DateTime) -> Result, Box> { + Ok(self.deleted_items.range(since..) .map(|(_key, id)| id.clone()) - .collect() + .collect()) } /// Returns the list of items that this calendar contains - async fn get_items(&self) -> HashMap { + async fn get_items(&self) -> Result, Box> { self.get_items_modified_since(None, None).await } diff --git a/src/provider.rs b/src/provider.rs index bcedd1d..43402e0 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -80,7 +80,7 @@ where // Step 1 - "Server always wins", so a delteion from the server must be applied locally, even if it was locally modified. let mut local_dels = match last_sync { None => HashSet::new(), - Some(date) => cal_local.get_items_deleted_since(date).await, + Some(date) => cal_local.get_items_deleted_since(date).await?, }; if last_sync.is_some() { let server_deletions = cal_server.find_deletions_from(cal_local.get_item_ids().await).await; @@ -97,8 +97,8 @@ where } // Step 2 - Compare both changesets... - let server_mods = cal_server.get_items_modified_since(last_sync, None).await; - let mut local_mods = cal_local.get_items_modified_since(last_sync, None).await; + let server_mods = cal_server.get_items_modified_since(last_sync, None).await?; + let mut local_mods = cal_local.get_items_modified_since(last_sync, None).await?; // ...import remote changes,... let mut conflicting_tasks = Vec::new(); diff --git a/src/traits.rs b/src/traits.rs index 9c5c9d6..cfde874 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -42,7 +42,7 @@ pub trait PartialCalendar { /// Returns the items that have been last-modified after `since` async fn get_items_modified_since(&self, since: Option>, filter: Option) - -> HashMap; + -> Result, Box>; /// Get the IDs of all current items in this calendar async fn get_item_ids(&mut self) -> HashSet; @@ -82,9 +82,9 @@ pub trait CompleteCalendar : PartialCalendar { /// Returns the items that have been deleted after `since` /// /// See also [`PartialCalendar::get_items_deleted_since`] - async fn get_items_deleted_since(&self, since: DateTime) -> HashSet; + async fn get_items_deleted_since(&self, since: DateTime) -> Result, Box>; /// Returns the list of items that this calendar contains - async fn get_items(&self) -> HashMap; + async fn get_items(&self) -> Result, Box>; } diff --git a/src/utils.rs b/src/utils.rs index d0b398d..cfcbe5f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -64,8 +64,13 @@ where { for (id, cal) in cals { println!("CAL {}", id); - for (_, item) in cal.lock().unwrap().get_items().await { - print_task(item); + match cal.lock().unwrap().get_items().await { + Err(_err) => continue, + Ok(map) => { + for (_, item) in map { + print_task(item); + } + }, } } } diff --git a/tests/caldav_client.rs b/tests/caldav_client.rs index df6cdf6..b03b600 100644 --- a/tests/caldav_client.rs +++ b/tests/caldav_client.rs @@ -48,7 +48,7 @@ async fn show_calendars() { let cal = calendar.lock().unwrap(); println!(" {}\t{}", cal.name(), id.as_str()); println!(" Most recent changes:"); - for (_id, task) in cal.get_items_modified_since(None, None).await { + for (_id, task) in cal.get_items_modified_since(None, None).await.unwrap() { my_tasks::utils::print_task(task); } }