From c70c006abd9069891baa462abe1edd6f184b9622 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Fri, 30 Jun 2023 22:38:18 -0400 Subject: [PATCH] Now returning duplicate database errors. --- src/morethantext/cache.rs | 5 ++++- src/morethantext/mod.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/morethantext/cache.rs b/src/morethantext/cache.rs index 3cb7366..d5d0f5e 100644 --- a/src/morethantext/cache.rs +++ b/src/morethantext/cache.rs @@ -43,7 +43,10 @@ impl Cache { pub fn commit(&mut self, data: Store) -> FromCache { let store = self.data.get_mut(ENTRY).unwrap(); for name in data.list() { - store.add(name).unwrap(); + match store.add(name) { + Ok(_) => (), + Err(err) => return FromCache::Error(err), + } } FromCache::Ok } diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 722df20..e574e40 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -146,6 +146,24 @@ mod mtt { let output = mtt1.session().await.unwrap(); assert_eq!(output.list(), [db1, db2]); } + + #[async_std::test] + async fn fail_on_duplicates() { + let dir = tempdir().unwrap(); + let mtt1 = start_db(dir.path()).await.unwrap(); + let mtt2 = mtt1.clone(); + let name = "unique_only"; + let mut store1 = mtt1.session().await.unwrap(); + let mut store2 = mtt2.session().await.unwrap(); + store1.add(name).unwrap(); + store2.add(name).unwrap(); + mtt1.commit(store1).await.unwrap(); + let output = mtt2.commit(store2).await; + match output { + Ok(_) => assert!(false, "Should have returned an error"), + Err(_) => (), + } + } } pub async fn start_db

(dir: P) -> Result