From 58ed923bc7a0f8c776da0ce831e907568d1cc3b0 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 23 Nov 2024 16:41:37 +0200 Subject: [PATCH] remove duplicated enums --- src/profile/identity.rs | 6 +++--- src/profile/identity/error.rs | 5 ++--- src/profile/identity/gemini.rs | 10 +++++----- src/profile/identity/gemini/auth.rs | 18 ++++++------------ src/profile/identity/gemini/auth/error.rs | 8 ++------ src/profile/identity/gemini/error.rs | 10 ++++------ 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/profile/identity.rs b/src/profile/identity.rs index 959a5d64..23c3ca02 100644 --- a/src/profile/identity.rs +++ b/src/profile/identity.rs @@ -29,16 +29,16 @@ impl Identity { Some(identity) => identity.id, None => match database.add(profile_id, true) { Ok(id) => id, - Err(reason) => return Err(Error::DatabaseAdd(reason)), + Err(reason) => return Err(Error::Database(reason)), }, }, - Err(reason) => return Err(Error::DatabaseActive(reason)), + Err(reason) => return Err(Error::Database(reason)), }); // Init gemini component let gemini = Rc::new(match Gemini::new(connection, profile_identity_id) { Ok(result) => result, - Err(reason) => return Err(Error::GeminiInit(reason)), + Err(reason) => return Err(Error::Gemini(reason)), }); // Done diff --git a/src/profile/identity/error.rs b/src/profile/identity/error.rs index ee50c871..338d50ac 100644 --- a/src/profile/identity/error.rs +++ b/src/profile/identity/error.rs @@ -1,6 +1,5 @@ #[derive(Debug)] pub enum Error { - DatabaseActive(sqlite::Error), - DatabaseAdd(sqlite::Error), - GeminiInit(super::gemini::Error), + Database(sqlite::Error), + Gemini(super::gemini::Error), } diff --git a/src/profile/identity/gemini.rs b/src/profile/identity/gemini.rs index a08f8802..61c8c36e 100644 --- a/src/profile/identity/gemini.rs +++ b/src/profile/identity/gemini.rs @@ -34,7 +34,7 @@ impl Gemini { // Init components let auth = match Auth::new(connection.clone()) { Ok(auth) => Rc::new(auth), - Err(reason) => return Err(Error::AuthInit(reason)), + Err(reason) => return Err(Error::Auth(reason)), }; let database = Rc::new(Database::new(connection, profile_identity_id.clone())); let memory = Rc::new(Memory::new()); @@ -62,7 +62,7 @@ impl Gemini { self.index()?; Ok(profile_identity_gemini_id) } - Err(reason) => Err(Error::DatabaseRecordCreate(reason)), + Err(reason) => Err(Error::Database(reason)), } } @@ -89,7 +89,7 @@ impl Gemini { pub fn index(&self) -> Result<(), Error> { // Clear previous records if let Err(reason) = self.memory.clear() { - return Err(Error::MemoryClear(reason)); + return Err(Error::Memory(reason)); } // Build new index @@ -97,11 +97,11 @@ impl Gemini { Ok(records) => { for record in records { if let Err(reason) = self.memory.add(record.id, record.pem) { - return Err(Error::MemoryIndex(reason)); + return Err(Error::Memory(reason)); } } } - Err(reason) => return Err(Error::DatabaseIndex(reason)), + Err(reason) => return Err(Error::Database(reason)), }; Ok(()) diff --git a/src/profile/identity/gemini/auth.rs b/src/profile/identity/gemini/auth.rs index b24240b4..29dc2b35 100644 --- a/src/profile/identity/gemini/auth.rs +++ b/src/profile/identity/gemini/auth.rs @@ -49,13 +49,7 @@ impl Auth { let profile_identity_gemini_auth_id = match self.database.add(profile_identity_gemini_id, url) { Ok(id) => id, - Err(reason) => { - return Err(Error::DatabaseRecordCreate( - profile_identity_gemini_id, - url.to_string(), - reason, - )) - } + Err(reason) => return Err(Error::Database(reason)), }; // Reindex @@ -71,11 +65,11 @@ impl Auth { Ok(records) => { for record in records { if let Err(reason) = self.database.delete(record.id) { - return Err(Error::DatabaseRecordDelete(record.id, reason)); + return Err(Error::Database(reason)); } } } - Err(reason) => return Err(Error::DatabaseRecordsRead(url.to_string(), reason)), + Err(reason) => return Err(Error::Database(reason)), } self.index()?; Ok(()) @@ -85,7 +79,7 @@ impl Auth { pub fn index(&self) -> Result<(), Error> { // Clear previous records if let Err(reason) = self.memory.clear() { - return Err(Error::MemoryClear(reason)); + return Err(Error::Memory(reason)); } // Build new index @@ -96,11 +90,11 @@ impl Auth { .memory .add(record.url, record.profile_identity_gemini_id) { - return Err(Error::MemoryIndex(reason)); + return Err(Error::Memory(reason)); } } } - Err(reason) => return Err(Error::DatabaseIndex(reason)), + Err(reason) => return Err(Error::Database(reason)), } Ok(()) diff --git a/src/profile/identity/gemini/auth/error.rs b/src/profile/identity/gemini/auth/error.rs index 4e29e02a..6e329b69 100644 --- a/src/profile/identity/gemini/auth/error.rs +++ b/src/profile/identity/gemini/auth/error.rs @@ -1,9 +1,5 @@ #[derive(Debug)] pub enum Error { - DatabaseIndex(sqlite::Error), - DatabaseRecordCreate(i64, String, sqlite::Error), - DatabaseRecordDelete(i64, sqlite::Error), - DatabaseRecordsRead(String, sqlite::Error), - MemoryClear(super::memory::Error), - MemoryIndex(super::memory::Error), + Database(sqlite::Error), + Memory(super::memory::Error), } diff --git a/src/profile/identity/gemini/error.rs b/src/profile/identity/gemini/error.rs index 255114a6..c004ce0b 100644 --- a/src/profile/identity/gemini/error.rs +++ b/src/profile/identity/gemini/error.rs @@ -1,9 +1,7 @@ #[derive(Debug)] pub enum Error { - AuthInit(super::auth::Error), - DatabaseIndex(sqlite::Error), - DatabaseRecordCreate(sqlite::Error), - MemoryClear(super::memory::Error), - MemoryIndex(super::memory::Error), - Certificate(Box), + Auth(super::auth::Error), + Certificate(Box), // @TODO + Database(sqlite::Error), + Memory(super::memory::Error), }