delegate child errors to parent handler

This commit is contained in:
yggverse 2024-11-20 09:27:40 +02:00
parent e1592425b9
commit f9e35553da
7 changed files with 11 additions and 12 deletions

View File

@ -3,7 +3,7 @@ mod error;
mod gemini; mod gemini;
use database::Database; use database::Database;
use error::Error; pub use error::Error;
use gemini::Gemini; use gemini::Gemini;
use sqlite::{Connection, Transaction}; use sqlite::{Connection, Transaction};
@ -35,7 +35,7 @@ impl Identity {
// 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(_) => return Err(Error::Gemini), Err(reason) => return Err(Error::Gemini(reason)),
}); });
// Done // Done

View File

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

View File

@ -6,7 +6,7 @@ mod memory;
use auth::Auth; use auth::Auth;
use database::Database; use database::Database;
use error::Error; pub use error::Error;
use memory::Memory; use memory::Memory;
@ -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(_) => return Err(Error::AuthInit), // @TODO Err(reason) => return Err(Error::AuthInit(reason)), // @TODO
}; };
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());

View File

@ -5,7 +5,7 @@ mod error;
mod memory; mod memory;
use database::Database; use database::Database;
use error::Error; pub use error::Error;
use memory::Memory; use memory::Memory;
use sqlite::{Connection, Transaction}; use sqlite::{Connection, Transaction};
@ -85,12 +85,11 @@ impl Auth {
match self.database.records(None) { match self.database.records(None) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
if self if let Err(reason) = self
.memory .memory
.add(record.url, record.profile_identity_gemini_id) .add(record.url, record.profile_identity_gemini_id)
.is_err()
{ {
return Err(Error::MemoryIndex); return Err(Error::Memory(reason));
} }
} }
} }

View File

@ -4,5 +4,5 @@ pub enum Error {
DatabaseRecordCreate(i64, String), DatabaseRecordCreate(i64, String),
DatabaseRecordDelete(i64), DatabaseRecordDelete(i64),
DatabaseRecordsRead(String), DatabaseRecordsRead(String),
MemoryIndex, Memory(super::memory::Error),
} }

View File

@ -1,5 +1,5 @@
mod error; mod error;
use error::Error; pub use error::Error;
use std::{cell::RefCell, collections::HashMap}; use std::{cell::RefCell, collections::HashMap};

View File

@ -1,6 +1,6 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
AuthInit, AuthInit(super::auth::Error),
DatabaseIndex, DatabaseIndex,
DatabaseRecordCreate, DatabaseRecordCreate,
MemoryIndex, MemoryIndex,