From 3179b6a33af82616e4496e187dac7b93b5134bee Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 8 Mar 2025 08:27:09 +0200 Subject: [PATCH] update error handle --- src/app.rs | 31 ++++++------------------------- src/main.rs | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5bfdce66..2941a86e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -260,36 +260,17 @@ impl App { } // Actions - pub fn run(&self) -> ExitCode { + pub fn run(&self) -> Result { // Begin database migration @TODO { - // Init writable connection - let mut connection = match self.profile.database.connection.write() { - Ok(connection) => connection, - Err(e) => todo!("{e}"), - }; - - // Init new transaction - let transaction = match connection.transaction() { - Ok(transaction) => transaction, - Err(e) => todo!("{e}"), - }; - - // Begin migration - match migrate(&transaction) { - Ok(_) => { - // Confirm changes - match transaction.commit() { - Ok(_) => {} // @TODO - Err(e) => todo!("{e}"), - } - } - Err(e) => todo!("{e}"), - } + let mut connection = self.profile.database.connection.write().unwrap(); + let transaction = connection.transaction()?; + migrate(&transaction)?; + transaction.commit()?; } // unlock database // Start application - self.application.run() + Ok(self.application.run()) } } diff --git a/src/main.rs b/src/main.rs index 1b6553aa..89296304 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,8 +8,23 @@ use profile::Profile; use std::rc::Rc; fn main() -> ExitCode { - match gtk::init() { - Ok(_) => App::build(&Rc::new(Profile::new().unwrap())).run(), - Err(_) => ExitCode::FAILURE, + match Profile::new() { + Ok(profile) => { + if let Err(e) = gtk::init() { + eprintln!("Failed to initialize GTK: {e}"); + return ExitCode::FAILURE; + } + match App::build(&Rc::new(profile)).run() { + Ok(result) => result, + Err(e) => { + eprintln!("Failed to initialize application: {e}"); + ExitCode::FAILURE + } + } + } + Err(e) => { + eprintln!("Failed to initialize profile: {e}"); + ExitCode::FAILURE + } } }