remove duplicated enums

This commit is contained in:
yggverse 2024-11-23 16:41:37 +02:00
parent a48f62eb13
commit 58ed923bc7
6 changed files with 22 additions and 35 deletions

View File

@ -29,16 +29,16 @@ impl Identity {
Some(identity) => identity.id, Some(identity) => identity.id,
None => match database.add(profile_id, true) { None => match database.add(profile_id, true) {
Ok(id) => id, 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 // Init gemini component
let gemini = Rc::new(match Gemini::new(connection, profile_identity_id) { let gemini = Rc::new(match Gemini::new(connection, profile_identity_id) {
Ok(result) => result, Ok(result) => result,
Err(reason) => return Err(Error::GeminiInit(reason)), Err(reason) => return Err(Error::Gemini(reason)),
}); });
// Done // Done

View File

@ -1,6 +1,5 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
DatabaseActive(sqlite::Error), Database(sqlite::Error),
DatabaseAdd(sqlite::Error), Gemini(super::gemini::Error),
GeminiInit(super::gemini::Error),
} }

View File

@ -34,7 +34,7 @@ impl Gemini {
// Init components // Init components
let auth = match Auth::new(connection.clone()) { let auth = match Auth::new(connection.clone()) {
Ok(auth) => Rc::new(auth), 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 database = Rc::new(Database::new(connection, profile_identity_id.clone()));
let memory = Rc::new(Memory::new()); let memory = Rc::new(Memory::new());
@ -62,7 +62,7 @@ impl Gemini {
self.index()?; self.index()?;
Ok(profile_identity_gemini_id) 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> { pub fn index(&self) -> Result<(), Error> {
// Clear previous records // Clear previous records
if let Err(reason) = self.memory.clear() { if let Err(reason) = self.memory.clear() {
return Err(Error::MemoryClear(reason)); return Err(Error::Memory(reason));
} }
// Build new index // Build new index
@ -97,11 +97,11 @@ impl Gemini {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
if let Err(reason) = self.memory.add(record.id, record.pem) { 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(()) Ok(())

View File

@ -49,13 +49,7 @@ impl Auth {
let profile_identity_gemini_auth_id = let profile_identity_gemini_auth_id =
match self.database.add(profile_identity_gemini_id, url) { match self.database.add(profile_identity_gemini_id, url) {
Ok(id) => id, Ok(id) => id,
Err(reason) => { Err(reason) => return Err(Error::Database(reason)),
return Err(Error::DatabaseRecordCreate(
profile_identity_gemini_id,
url.to_string(),
reason,
))
}
}; };
// Reindex // Reindex
@ -71,11 +65,11 @@ impl Auth {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
if let Err(reason) = self.database.delete(record.id) { 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()?; self.index()?;
Ok(()) Ok(())
@ -85,7 +79,7 @@ impl Auth {
pub fn index(&self) -> Result<(), Error> { pub fn index(&self) -> Result<(), Error> {
// Clear previous records // Clear previous records
if let Err(reason) = self.memory.clear() { if let Err(reason) = self.memory.clear() {
return Err(Error::MemoryClear(reason)); return Err(Error::Memory(reason));
} }
// Build new index // Build new index
@ -96,11 +90,11 @@ impl Auth {
.memory .memory
.add(record.url, record.profile_identity_gemini_id) .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(()) Ok(())

View File

@ -1,9 +1,5 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
DatabaseIndex(sqlite::Error), Database(sqlite::Error),
DatabaseRecordCreate(i64, String, sqlite::Error), Memory(super::memory::Error),
DatabaseRecordDelete(i64, sqlite::Error),
DatabaseRecordsRead(String, sqlite::Error),
MemoryClear(super::memory::Error),
MemoryIndex(super::memory::Error),
} }

View File

@ -1,9 +1,7 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
AuthInit(super::auth::Error), Auth(super::auth::Error),
DatabaseIndex(sqlite::Error), Certificate(Box<dyn std::error::Error>), // @TODO
DatabaseRecordCreate(sqlite::Error), Database(sqlite::Error),
MemoryClear(super::memory::Error), Memory(super::memory::Error),
MemoryIndex(super::memory::Error),
Certificate(Box<dyn std::error::Error>),
} }